Automated, scheduled FTP transfer
Share on Facebook

My automatic back-up routine generates log files in HTML format. I wanted them to be uploaded to the internet on a daily basis, so that the back-up report can be viewed on-line. The following instructions are written from the perspective of an Ubuntu Desktop user.


To achieve this, I created the following shell script, using the Gedit text editor, called it, and saved it in my home directory.


ftp -i -n [hostname] <<EOF
user [username] [password]
cd [folder where you want to place files]
lcd [folder where the files are stored locally]
mput *.log


Replace the place-holders with the correct information. On line 4, remember that you need to enter the folder path relative to where your FTP log-in normally takes you.


On line 6, I use "*.log" because the back-up log files have the extension ".log". The asterisk represents a wild-card. This means that all files ending in ".log" will be transferred.


Save the script and mark it as executable, either by right-clicking it and using the Properties tab in Nautilus, or by entering chmod +x [scriptname] in a Terminal session.


Next, you need to add this to your crontab entries. The easiest way to do this is via the Scheduled Tasks utility which is available from the Ubuntu repositories. This uses straight-forward English to append lines to your crontab-entries.


A crontab entry which schedules script excecution every day at midnight will look like this:


0 * * * * bash [path to script file] >/dev/null 2>&1


The >/dev/null 2>&1 part merely stops crontab trying to email you to say that the script has run. It can be left off, if desired.


This method can be used to provide an automatic, scheduled, remote-backup facility for your local files.