If you’ve been using linux for a while you have probably used SCP or RSYNC to transfer files between two linux servers. These methods work very well and I created another post for using a non standard port with SCP…but what if the other server doesn’t support RSYNC or SCP? Or maybe you just like using FTP or want to create a script to do automatic uploads? LFTP was my choice because it displays a nice progress bar with transfer rate.
LFTP is great to use to transfer just one file or an entire directory structure. I recently used this to transfer a file from one server to another but because of the file size using the standard FTP hash created an endless SSH terminal of hash marks…I wanted something simple that would show a progress bar and transfer rate, in comes LFTP.
I’ve added a tutorial, How to install and configure an FTP Server (vsFTP) on CentOS 6 in 5 minutes
CentOS which is my linux distribution of choice for hosting environments comes with LFTP already installed so I’m assuming you are using CentOS.
The full command we will be using is below and I will break it down step by step.
Here’s our example data:
In this example we will be mirroring the /home/olduser/public_html from oldserver.com to /home/newuser/public_html on newserver.com. The FTP username on oldserver.com is olduser with the password being oldpassword.
lftp -u olduser,oldpassword -e 'mirror /home/olduser/public_html /home/newuser/public_html' ftp.oldserver.com
If the above code is ran from the new server (newserver.com) this will mirror ALL files in /home/olduser/public_html to /home/newuser/public_html.
You can optionally supply these commonly used arguments:
–reverse (or just -R)
This will mirror files from /home/newuser/public_html to /home/olduser/public_html ON oldserver.com. This is commonly used to PUSH files from the server you are issuing the command on to what we are using in this example as our oldserver.com. Be careful if using -R as a lowercase -r tells lftp to not go into subdirectories.
lftp -u olduser,oldpassword -e 'mirror --reverse /home/newuser/public_html /home/olduser/public_html' ftp.oldserver.com
–delete (or just -e)
This will remove any files it doesn’t find on the remote server.
This will mirror only newer files on the server
–include (or just -i)
This will allow you to mirror only specific files. In the example below we will only be mirroring .html, .css, and .js files from /home/olduser/public_html RECURSIVELY to /home/newuser/public_html.
lftp -u olduser,oldpassword -e 'mirror -i ".(html?|css|js)$" /home/olduser/public_html /home/newuser/public_html' ftp.oldserver.com
There are TONS of other arguments you can use including creating scripts that you can use with lftp.
–verbose (or just -v)
If you want it to output a list of all the files as they are transferred you can use the verbose argument which will give you something similar to this image to the left.
For more information visit the LFTP website: