Bash Script Android : One click upload of pictures/videos from Galaxy SIII to Qnap

If you are like me, you end up with hundreds of photos and videos every weekend in your camera, that you wish could be transferred to your Qnap box or other ftp server quickly with one click.

Now I know , there is Qfile App from Qnap but that doesn’t let you choose All files in one go, and having to select say 70 files by clicking on each one is not very convenient. There are also programs like FTPCafe that let you rapidly upload by letting you select multiple files, but many clicks are involved and it doesn’t delete the uploaded media from your phone.

A quicker solution is to use the Linux commands that android systems provide you through busy box. Commands provided through busy box are not fully fledged commands but they get the job done. For now we are interested in ftpput that is built in SIII, I am not sure on the other android phones, but chances are they should have ftpput too. The Ftpput is not like fully fledged version so it doesn’t support –dir to change to remote directory but that’s not a problem.

You can conveniently write a small 6 lines bash script to copy all your media from phone to Qnap with 1 click, using ftpput . To write , edit and execute a bash script on your Android phone, you will need an app like Smanager ( Script manager). It will let you write and execute bash Scripts on android systems. It’s free ( or ad sponsored maybe) and can be installed for free from Google Play.

1. Install Smanager through Google Play.

2. In a directory of your choice, create a new file called upload.

3. Edit the file as Text and input the following lines.

cd /mnt/sdcard/DCIM/Camera
for fil in *.*
do
ftpput -v --user=myusername --pass=secret 192.168.2.19 /share/MD0_DATA/Multimedia/uploads/$fil $fil
mv $fil ./uploaded/$fil
done

The first line changes the directory to your default photoroll. In SIII the photoroll is at /mnt/sdcard/DCIM/Camera. You will have to change it to your default photo location. The 4th line uploads to directory Multimedia/uploads. Change user name, password , server ipaddress and upload location to match your installation.
The 5th line is optional, i just prefer to have all the uploaded media moved to a directory called upload. Actually In my script I delete the file once it’s uploaded to Qnap.

4. Click on the file upload and Smanager gives you the option to Run it.

Screenshot_2012-12-01-15-00-23.png

Run it and it quickly copies all the files to your Qnap box. You can see the output also in the terminal window to see what your script is doing.

Screenshot_2012-12-01-15-00-38.png

Now everytime you want to upload your media, you just have to click on your upload file and run it. I am assuming you are connected through wifi to the network your qnap resides on, in my case ftpput couldn’t resolve a hostname into ipaddress.

In case you are feeling like experimenting more with your Android system and wondering how many Unix command are avaialble for you to write script on SIII, here is a list of commands available through busybox on my SIII. It’s good to have a program like dropbear Server II to get access to your Android terminal on PC ( I use Putty on windows) so you can make use of PC keyboard.

[, [[, ash, awk, base64, basename, blkid,
        bunzip2, bzcat, bzip2, cal, cat, chat, chattr,
        chgrp, chmod, chown, chroot, chrt, cksum,
        clear, comm, cp, crond, crontab, cut, date,
        dd, depmod, devmem, df, diff, dirname, dmesg,
        dnsd, dnsdomainname, dos2unix, dpkg, dpkg-deb,
        du, echo, egrep, env, ether-wake, expand,
        expr, fakeidentd, fdflush, fdformat, fdisk,
        fgrep, find, fold, free, freeramdisk, fsck,
        fsync, ftpd, ftpget, ftpput, getopt, grep,
        groups, gunzip, gzip, hd, head, hexdump,
        hostid, hostname, httpd, hwclock, id,
        ifconfig, ifenslave, inetd, inotifyd, insmod,
        install, ionice, iostat, ip, ipaddr, ipcalc,
        iplink, iproute, iprule, iptunnel, kill,
        killall, killall5, less, ln, logname, losetup,
        ls, lsattr, lsmod, lsof, lsusb, lzop, lzopcat,
        md5sum, microcom, mkdir, mkdosfs, mke2fs,
        mkfifo, mkfs.ext2, mkfs.vfat, mknod, mkswap,
        modinfo, modprobe, more, mount, mountpoint,
        mt, mv, nameif, nanddump, nandwrite, nc,
        netstat, nice, nmeter, nslookup, ntpd, od,
        patch, pgrep, pidof, ping, ping6, pkill, pmap,
        powertop, printenv, printf, ps, pscan, pwd,
        rdate, rdev, readahead, readlink, realpath,
        renice, reset, rev, rfkill, rm, rmdir, rmmod,
        route, run-parts, script, scriptreplay, sed,
        seq, setkeycodes, setlogcons, setsid, sha1sum,
        sha256sum, sha512sum, showkey, sleep, smemcap,
        sort, split, stat, strings, stty, sum,
        swapoff, swapon, sync, sysctl, tac, tail, tar,
        tee, telnet, telnetd, test, tftp, tftpd, time,
        timeout, top, touch, tr, traceroute,
        traceroute6, tty, ttysize, tunctl, umount,
        uname, uncompress, unexpand, uniq, unix2dos,
        unlzop, unzip, uptime, usleep, uudecode,
        uuencode, vconfig, vi, watch, wc, wget, which,
        who, whoami, whois, xargs, zcat