automate transfer of tar files over FTP

5,595

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:
5,595

Related videos on Youtube

agmb
Author by

agmb

Updated on September 18, 2022

Comments

  • agmb
    agmb almost 2 years

    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!

  • agmb
    agmb almost 12 years
    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
  • Steve Kroon
    Steve Kroon almost 12 years
    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
    Steve Kroon almost 12 years
    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.