Auto backup files from the Samsung NX300 camera in the background

This would not have been possible without Georg Lukas' work!

  • Always-On wifi

    • Connect the camera to the wifi the regular way (for me only 2.4ghz wifi worked to automatically connect)

    • Find the corresponding settings file in /mnt/ubi1/data/var/lib/connman/*/settings (note down the folder name for the connection you automatically want to connect to)

    • Create the wpa_supplicant.conf file in /mnt/mmc/:

      nx300:/mnt/mmc# cat /tmp/wpa_supplicant.conf 
      config_methods=physical_display virtual_push_button keypad
    • Append the following to

      # Always on wifi
      cp /mnt/mmc/wpa_supplicant.conf /tmp/
      /usr/bin/ start NL 0x8210 >> /mnt/mmc/wifi.log 2>&1
      /usr/sbin/connmand -W nl80211 -r
      sleep 2
      #dbus-send --system --type=method_call --print-reply --dest=net.connman / net.connman.Manager.GetServices|grep service >> /mnt/mmc/wifi.log 2>&1 
      dbus-send --system --type=method_call --print-reply --dest=net.connman /net/connman/service/wifi_a0219572b25b_7777772e6c656d6d737465722e6465_managed_psk net.connman.Service.Connect >> /mnt/mmc/wifi.log 2>&1
  • FTPd (started via inetd)

    • Make inetd start ftpd automatically by appending the following to

      # Create inetd config file that activates ftpd
      echo "21 stream tcp nowait root ftpd /usr/sbin/ftpd /mnt/mmc/DCIM/" > /mnt/mmc/inetd.conf
      # start inetd (in background) that spawns ftpd on demand
      /usr/sbin/inetd /mnt/mmc/inetd.conf
    • On a remote host periodically poll (less elegant) for new files (if the camera is on-line). The second line purges the mirrored files from the camera so that they do not get downloaded again if deleted from the backup:

      while true; do sleep 5 && ping -q -c 3 nx300 > /dev/null && wget -q -m ftp://nx300/ ; done
      #(sleep 1; echo -e "cd /mnt/mmc/DCIM/100Photo/ && rm SAM_0158.JPG SAM_0159.JPG";) | nc -q 5 nx300 23
    • If you additionally want to only mirror files that are newer than a sentinel file (e.g. because you might want to be allowed to delete files locally without re-mirroring the file again), run:

      ## Mirrors files from the nx300 samsung camera to the local machine. The set of files mirrored is the subset of files newer than the given sentinel.
      ## License see
      ## mirrorers the files from the camera stored in the 100PHOTO/ folder int the local 100PHOTO/ folder
      lftp nx300 -e "set ftp:use-feat off; mirror --newer-than=100PHOTO/.sentinel 100PHOTO 100PHOTO; quit"
      ## Keep the last (newest) mirrored file at a sentinel.
      ## (Do not just store the name of the file because the original file can be touched (e.g. modified by an image editing program) on the local end
      cp -a 100PHOTO/`ls -tp 100PHOTO/ | grep -v /$ | head -1` 100PHOTO/.sentinel
    • However, I have found that ftpd/lftpd do not correctly preserve the ctime/mtime/... when transfering the file. Thus, the sentinal approach does not work reliably.

  • inotifywait

  • Install vsftpd on a raspberry pi

    • apt-get install vsftpd && mkdir -p /var/ftp/incoming && chown root:root /var/ftp && chown ftp:ftp /var/ftp/incoming

    • Add anon_upload_enable=YES, write_enable=YES, anonymous_enable=YES, anon_root=/var/ftp and anon_umask=022 to /etc/vsftpd and restart vsftpd

  • The final looks like:

    mkdir -p /dev/pts
    mount -t devpts none /dev/pts
    # Start telnet server
    telnetd -l /bin/bash -F > /mnt/mmc/telnetd.log 2>&1 &
    # Create inetd config file that activates ftpd
    echo "21 stream tcp nowait root ftpd /usr/sbin/ftpd /mnt/mmc/DCIM/" > /mnt/mmc/inetd.conf
    # start inetd (in background) that spawns ftpd on demand
    /usr/sbin/inetd /mnt/mmc/inetd.conf
    # automatically start wifi
    cp /mnt/mmc/wpa_supplicant.conf /tmp/
    /usr/bin/ start NL 0x8210
    /usr/sbin/connmand -W nl80211 -r
    sleep 2
    dbus-send --system --type=method_call --print-reply --dest=net.connman /net/connman/service/wifi_a0219572b25b_7777772e6c656d6d737465722e6465_managed_psk net.connman.Service.Connect
    # start
    # (TODO: inline the script?)
    /mnt/mmc/ > /mnt/mmc/mirror.log & 2>&1
    # copy any file the script might have missed in previous runs
    for f in /mnt/mmc/DCIM/100PHOTO/*.JPG; do file=`basename $f` && ftpput $TARGET incoming/$file $f && rm $f; done

Want to comment? Send me an email to blog-comments-2016 at lemmster d.t de and I'll paste it here (I won't publish your address). Why don't you use an external comment service like disqus, you ask? Well, I like to keep this site under my control, comments included. You can use markdown to format your comment.

Comment by: Bill Hart Date: 2014-09-29 09:57:17


Just a couple of updates on hacking the Samsung NX cameras. I'm using the NX300M so comments refer to them specifically. Samsung have removed the exploit from the last couple of firmware revisions - from 1.11 on. However you can find and install older firmware and 'upgrade' to an older version.

It looks like they have removed from '/etc/' the code which looked for and executed a file on the SD card. I would build a modified version of their firmware but the instructions from the developer site are fairly poor and it looks like a day or so's work to get it to build.

Wifi stuff worked well for me (saved me a few hours at least), I'd wondered if you'd considered using rsync rather than ftp ? Its supposed to be part of busybox.

cheers Bill Hart

Comment by: Lee Olds Date: 2014-12-30 19:02:17

Hello, Thanks for describing how you did this. I have the NX300 (not NX300M). In response to Bill Hart's comment, I've tested the hack on the latest NX300 firmware (1.45), and it still works fine there. Also, I've seen page describing how someone set up an auto-backup on NX300 using the ssh client that comes in the camera.