Using LFTP (FTP) to mirror/transfer files from one server to another

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 Single FileLFTP 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.

Update:

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:

Username olduser
Password oldpassword
Source Server ftp.oldserver.com
Source Path /home/olduser/public_html
Local Server newserver.com
Local Path /home/newuser/public_html

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.

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.

 

–delete (or just -e)

This will remove any files it doesn’t find on the remote server.

–only-newer

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.

There are TONS of other arguments you can use including creating scripts that you can use with lftp.

 lftpfiles

–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:

http://lftp.yar.ru/lftp-man.html

Myles

Orlando, FL

Did this post help you?

Give back and rate it for me!

Related Posts

  • Thanks

  • How would you mirror all the png files in all subdirectories eg /images/folder1/*.png into one remote directory eg /images/pngs/ without syncing the source subdirectory (in this case folder 1)?

    So far I have:

    lftp -u user,password -e ‘mirror -c –parallel=10 –verbose –only-newer -f /images/folder*/*png /images/pngs;bye’ 192.168.33.10

    but it still creates the subdirectory in the target directory.

  • CPG

    2 years later, but I didn’t know I needed help until now. Thanks for giving short clear examples.

  • Pingback: How to install and configure an FTP Server (vsFTP) on CentOS 6 in 5 minutes « sMyl.es()