lftp crontab linux options how to

first lets make a working directory. Open up ssh or go to the command console and type

cd /var/

Create a directory here

mkdir test

now create a file with vi (or use whatever editor you like, I personally hate vi but it’s what it on my server)

vi myFile.exe

Now type in the following:

#!/bin/bash
/usr/local/bin/lftp -e ‘lcd /var/test/ && set ftp:ssl-protect-data yes && set ftp:passive-mode yes && open ftp://server:port -d -u “username”,”password” && mirror “.” && exit’
If using vi, type ESC then :wq to write the file.  you should now be back at the command console.
If you type ls you should see the file listed now.
Now type:
chmod u+x myFile.exe
Now your file is ready to execute.  You can type ./myFile.exe from the command line and it should run the lftp commands.  Just a note, the mirror command above will copy all the files (not recursively).  The lcd command changes the local directory where files will be downloaded to.
You’ll notice that I have the full path to the lftp program.  You’ll need that.  If you don’t know where it’s installed you can do:
find / -name ‘lftp’
Now let’s create the crontab. Type:
crontab -e
That should open up your crontab file. Enter a new line and enter:
30 18 * * * unbuffer /var/test/myFile.exe > /var/test/log.txt
That should do it.
Now, all the files on your ftp server will be downloaded to your computer at 6:30pm every day.  Pretty nifty!
Advertisements