Mauriat Miranda     mjmwired

Automated FTP Script

I’ve been doing some development for some embedded Linux devices which only support ftp and telnet. In order to automate transfer of binaries from my Fedora development host to the target embedded device I’m using this handy ftp script: pushftp.sh

#!/bin/bash

# arg1 = dest hostname
# arg2 = local file
# arg3 = dest dir

HOST=$1
SRCFILE=$2

USER=root
PASSWD=password
#DESTDIR=/usr/local/data
DESTDIR=$3

ftp -inv $HOST<<ENDFTP
user $USER $PASSWD
cd $DESTDIR
bin
put $SRCFILE
chmod 755 $SRCFILE
bye
ENDFTP

Then I added something like this to my Makefile after cross-compiling:

push:
        sh ~/bin/pushftp.sh $(TEST_BOX) $(APP_BIN) /usr/local/data

So after I run make all, I run make push. I still need to telnet to the host to test/debug the application, but this makes the process much faster (and less error-prone).

I’m just noting this for myself, hopefully it’s useful to someone else.

Posted in: Development, Miscellaneous, Server, Tips,

1 Comments:

  • Rob Russell on December 19, 2010 - 01:01 AM

    Nice, but have you considered making a local mirror of the remote file structure which consists of empty files that get touched after the corresponding data is delivered by ftp? Then you could send only files that have changed since the last build.

    If the push target is fast enough (and does nothing when no files have changed) then you could run make push every couple seconds in a background script while you’re developing. I had to do something similar for some PHP development a while ago, but I only had a couple files so I didn’t need to generalize it.