1 What is lftp?

2 Why do I want to use it?

3 Installation on CentOS 5

4 Installation on Ubuntu

5 Mirroring from local directory to remote ftp from command line

6 Mirroring from local directory to remote ftp from a script

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 , -e "mirror --reverse  --delete --only-newer  " 

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.

  1. To fix these drawbacks we will want to create a script that has all of the variables in it.
  2. Edit a file, lets call it lftpcommand.txt (you can all it whatever you want).
  3. In it place the following:
    open
            user
            mirror --reverse --delete --only-newer
            
  4. Now to run the command we will use:

    lftp -f  lftpcommand.txt

Topics

Related Articles