In this article I’m going to teach you how to use the lftp mirror command in order to copy your website files from another web host to your VPS (Virtual Private Server) or dedicated server with InMotion Hosting.
The Linux lftp command is a sophisticated FTP/HTTP client that is also capable of being able to mirror the entire contents of a remote website to your local server, or vice-versa. Using the lftp command on your server can help save you time when copying website files from a remote server.
You can directly transfer the files right to your server, instead of having to first locally copy files to your desktop, just to upload them again to your server. Typically web hosts will have higher bandwidth connections than your residential Internet connection, so directly transferring files between two servers with lftp is an ideal method to use if you’ve got a lot of files to transfer.
In order to follow along with the steps below you’ll need to have either a VPS or dedicated server so that you have SSH access to your server in order to run the lftp mirror command.
lftp mirror remote files to your server
Using the steps below I’ll show you how to quickly connect to a remote server where you might have website files stored, and then mirror the entire contents of that website to your server using the lftp mirror commands.
- Login to your server via SSH with the cPanel user you’d like to copy remote files to.
- After logging into SSH run the following command to get to your public directory:
You can now run the following command to ensure you’re in the right directory:
You should get back something like this:
In most cases your /public_html/ directory should be empty if you haven’t placed any files on the server yet. If you wanted to do your file transfer to another directory such as a sub-directory, you would want to use the cd command again to end up in that directory.
- In this example we’re going to connect to our old remote server at example.com using the FTP username userna5 and the password of passWORD. Run the following command to begin our lftp session to this remote server:
lftp -u userna5,passWORD example.com
If your FTP password includes special characters such as $ or ) you’d want to leave off the password like this, then type it in manually when prompted:
lftp -u userna5 example.com
In some cases certain servers will now allow you to connect with lftp with the default settings, you can try the following to connect to these type of servers:
lftp -u userna5,passWORD example.com -e “set ftp:ssl-allow off”
You should end up at the lftp prompt when you’ve successfully connected to the remote server, it would look like this:
- Now that you have a FTP connection established to the remote server, the next step is to change directories into the remote directory with your files. To view all of the folders on the remote server you can use the following command:
It should give you back something similar to this:
lrwxrwxrwx 1 userna5 userna5 33 Jul 16 2011 access-logs -> /usr/local/apache/domlogs/userna5
drwxr-xr-x 2 userna5 userna5 4096 Nov 20 2010 backup
drwxr-x— 4 userna5 12 4096 Jan 28 14:14 etc
drwxr-x–x 11 userna5 userna5 20480 Jan 10 12:52 mail
drwxr-x— 11 userna5 99 4096 Jan 28 14:15 public_html
drwxr-xr-x 10 userna5 userna5 4096 Jan 22 13:56 tmp
lrwxrwxrwx 1 userna5 userna5 11 Jul 16 2011 www -> public_html
In this case our website files are stored in the /public_html/ directory so we can run the following command to get to this directory:
- Now that you’ve changed into the remote directory where you’d like to mirror all of the files to your server from, run the following command to begin the file transfer:
This uses the lftp mirror command to mirror the entire remote directory to our current local directory that we changed to prior to starting the transfer. The -c option is for continue and allows the mirror to continue from a previously failed transfer.
After the file transfer has completed you should see the status of the full transfer which looks something like this:
lftp email@example.com:/public_html> mirror -c
Total: 175 directories, 1316 files, 0 symlinks
New: 1316 files, 0 symlinks
20750001 bytes transferred in 20 seconds (1010.8K/s)
To be removed: 1 directory, 0 files, 0 symlinks
- Type either exit or quit to leave the lftp session:
lftp firstname.lastname@example.org:/public_html> exit
You should now know how to use the lftp mirror command on your VPS or dedicated server in order to transfer over website files from a remote server.