How to backup files to a remote FTP server using lftp

Last updated on July 3, 2020 by Dan Nanni

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 back up local files or directory trees to a remote FTP server, you can proceed as follows.

Install lftp on Linux

For Debian-based Linux:

To install lftp on Ubuntu, Debian or Linux Mint:

$ sudo apt-get install lftp

For Red-Hat-based Linux:

To install lftp on CentOS, Fedora or RHEL:

$ sudo yum install lftp

Back up Files to a Remote FTP Server with 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:[email protected]$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" 

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean