Take the 2-minute tour ×

Every day I have a script making .tar files of aparticualr directory. Once every day, I would like to transfere the new tar file made that day to a remote server over FTP. I would like to make this process automated.

What would be the best way of going about this? Can a bash script be written for this and scheduled it with cron? Is there a tool/app/software that can do this?

Thanks very much!

share|improve this question

1 Answer 1

Usually these kind of things are best done from the command line

put the example below in a new file under /etc/cron.daily/ and chmod +x filename , for it to be executable so that it can be automatically run on on a daily basis.

lftp -e 'put /home/path/yourfile.tar; bye' -u user,password ftp.theserver.com

the -e command is to allow you to enter a series of commands. The commands to be run are declared within the ' ' signs, in this example two commands are run in succession each command is separated by the ; sign. The first command uploads a file, the second command disconnects from the ftp server once the upload is complete.

If one would want to add an additional command, for example to browse to a another folder simply add the change directory command , "cd folder1/folder2;" in our example the new command would look like this:

lftp -e 'cd folder1/folder2; put /home/path/yourfile.tar; bye' -u user,password ftp.theserver.com

lftp can take script files as input allowing you to create separate files with commands for it to execute when using the -f option if you feel like having the commands run my lftp separated into a specific file.

if you want to see what commands are available this can be help for generic ftp commands. Commands specific for lftp can be found in the lftp man page

share|improve this answer
sorry, i'm still new to terminal commands. Can you please explain it in more detail. Are those commands inside a bash file that is scheduled in cron? In the 'put /home/path/yourfile.tar; bye' what is the ; bye for? also what are the -e and -u commands mean and how will i be able to specify a directory in the ftp server? ~Thx –  agmb Aug 14 '12 at 13:43
The ; is to separate the 2 commands inside the quotes. The -e is for specifying commands to execute, and the -u is to say the username and password is coming next. Usually you can find what the various flags (-e, -u, etc.) do by running man command, e.g. man lftp on the command line. –  Steve Kroon Aug 15 '12 at 11:23
By putting the commands in a text file, say lftpbackup inside the /etc/cron.daily/ folder, and then running chmod +x lftpbackup, you will cause the commands in lftpbackup to be executed daily. –  Steve Kroon Aug 15 '12 at 11:25

Your Answer


