lftp – a better FTP client

I’ve been backing up my data using rsync, but when your data directory size has reached 90 GB, it can be pretty slow at times.

So I looked around, and found lftp. Backing up with it is very simple :

lftp -u myusername,mypassword -d -e “mirror -vnR /the/source/directory /the/target/directory” the.ftpserver.com

Explanation of the switches

-u : I think it’s quite clear, put your username & password on the command line, so this can be automated

-d : turn on debugging. Once you’re happy that lftp is running smoothly every single time, you can omit this.

-e : define the command to be done by lftp.

mirror : mirror the source into the target. Very nifty.

-v : be verbose.

-R : reverse mirroring – lftp will issue PUT command (upload) into the FTP server. Otherwise, the mirror switch will cause lftp to issue GET command (download) from the FTP server.

-n : just upload newer files (saves time)

A few tips

1. lftp seems to hang ? Try putting set ftp:passive-mode off on /etc/lftp.conf

Some FTP servers expect active ftp connection, and hung on passive ones. At least the one in my Mac OS X shows this behaviour (tnftpd).

2. For even faster backup speed, try putting set ftp:sync-mode off in the /etc/lftp.conf file.

This will cause lftp to enable pipelining; however, be advised that not all FTP servers nor all routers can handle this.

Since setting up FTP server is pretty easy (hint: on ubuntu; aptitude install gproftpd, on windows; download & install filezilla), I can backup my data to more machines now. And the backup speed is also faster. I just need to have lftp on my laptop.

And, do you know that lftp can handle seven file transfer protocols : ftp, ftps, http, https, hftp, fish, sftp and file? This is the swiss army knife of file transfer. Very useful. Kudos to Alexander V. Lukyanov for this.

9 thoughts on “lftp – a better FTP client

  1. bos, klo lftp ini bisa dipake buat saling replikasi data antara 2 server sql ndak ya? (maklum newbie di IT) atau bisa disarankan aplikasi lain? matur nuwun

  2. @silent – wput looks good as well. It’s always nice to have more alternatives.
    @walikan – bisa sekali, dan cenderung lebih bisa diandalkan.
    @All – the following is an email from Terry, and my reply :

    Hi Terry,

    Interesting, I didn’t experience the problem.

    Upon further research, it seems that your computer may have the setting “ftp:use-quit” set to “false” in /etc/lftp.conf or in ~/.lftprc

    Try changing it to “true”, and you should be ok.

    Cheers, HS

    > Dari: Terry
    > Email: xxxxxxxxxxxxxxxx
    > Feedback: Hi,
    > I spotted your post about lftp after doing some research & wondered if you might be able to offer some small assistance please – I found your lftp command for mirroring here:
    > http://harry.sufehmi.com/archives/2007-08-30-1523/
    > The only thing I found that was missing at the end of it was that it leaves lftp logged in at the end of the seesion – have you any idea what I need to add to the end to log out of lftp?
    > Many thanks for your assistance, Terry

  3. lftp -u myusername,mypassword -d -e “mirror -vnR /the/source/directory /the/target/directory” the.ftpserver.com ;exit

    😀 close and exit from lftp session at end of work

Leave a Reply

Your email address will not be published. Required fields are marked *