Getting Started with LFTP

What is lftp?

lftp is a sophisticated ftp/http client, file transfer program supporting a number of network protocols.

Why do I want to use it?

You have a number of files you need to keep in sync with a remote system that does not support a protocol such as rsync

Installation on CentOS 5

lftp is included with the stock repo for CentOS 5 this makes installation very easy!

All you need to do is install it with yum

yum install lftp

Installation on Ubuntu

sudo apt-get install lftp

Mirroring from local directory to remote ftp from command line

To mirror from a local directory to a remote ftp account you would want to run the following

lftp -u <username>,<password> -e "mirror --reverse --delete --only-newer <local dir> <remote dir>" <ftp server>

Where you replace the following variables:

Variable Replace With
<username> myusername
<password> secret123
<local dir> Directory where your files are
Example: /home/user/files
<remote dir> The remote directory to upload to
Example: /
<ftp server> The FTP Server you are connecting to
Example: ftp.mydomain.com

You should see a status screen that shows you the uploads. Try running it again, you will see nothing is transfered because they are already there!

Mirroring from local directory to remote ftp from a script

Great now everything is working correctly, however doing it from command line has a few drawbacks. First, you have to type it in everytime, this can be a pain. Second, your username and password would be saved in your history.

To fix these drawbacks we will want to create a script that has all of the variables in it.

Edit a file, lets call it lftpcommand.txt (you can all it whatever you want).

In it place the following:

open <ftp server>
user <username> <password>
mirror --reverse --delete --only-newer <local dir> <remote dir>

Now to run the command we will use:

lftp -f lftpcommand.txt