How to backup files to a remote FTP server using lftp

lftp is a command-line FTP client with several advanced file transfer features. For example, lftp can upload or download a whole directory tree recursively and selectively, or resume interrupted file transfers. A popular use case of lftp is to mirror local files or folders to a remote FTP server. While rsync is a popular mirroring software tool, it uses its own file synchronization protocol, and so does not work over FTP.

If you would like to backup local files or directory trees to a remote FTP server, you can proceed as follows.

To install lftp on Debian, Ubuntu or Linux Mint:

$ sudo apt-get install lftp

To install lftp on CentOS, Fedora or RHEL:

$ sudo yum install lftp

Now go ahead and run iftp command as follows. Note that $username, $password and $ftp_hostname need to be populated according to your FTP server setup.

$ lftp -c "set ftp:list-options -a;
open ftp://$username:$password@$ftp_hostname;
lcd /path/to/local/directory;
cd /path/to/remote/directory/in/ftp/server;
mirror --reverse --delete --parallel=3 --older-than='now-7days' --exclude-glob .git"
  • "--reverse" option means uploading files to a remote FTP server.
  • "--delete" option means removing files not present in the source directory.
  • "--parallel=3" option means uploading upto 3 files in parallel.
  • "--exclude-glob .git" option means excluding matching folders (e.g., .git).
  • "--older-than='now-7days'" option means uploading files which were modified more than seven days ago.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

2 thoughts on “How to backup files to a remote FTP server using lftp

  1. A much better way, IMHO, is to use the -f option for lftp and have the script of what needs to be done run from a file. Your recommended method might work for one or two copies, but if you are a pro system admin and you are doing this over and over again, you'll want to organize things into script files and the -f option lets you do that cleanly.

  2. Hi,

    Really good guide, thanks.

    This helped me backup my MP3s from a desktop to a NAS drive. Using LFTP, very efficient. Trouble is, it failed on any file with an apostrophe in the name, about one in every 5 files of 900. The NAS drive takes the same files if I do the move over a GUI with no issues, either individually or as part of a group cut and paste.

    Any clues?

Leave a comment

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