How to Copy Files from One Server to Another using SSH Command

When it comes to migrating WordPress blog from one server to another, process is fairly simple. I have already explained it in detailed over here, and in nutshell, we have to migrate:

  • WP-content folder
  • and Old database

For a new or a small website, this process can easily be done by using a free FTP client like FileZilla or Cyberduck. But, when you are dealing with a large site or migrating your website to a new hosting,it’s a good idea to use ssh/sFTP to transfer files from one server to another. In my case, I was transferring Wp-Content folder of epostakur from private VPS to WPEngine.

My WP-content folder was around 2GB, and manually transferring folder is time-consuming. So, I used SSH and sFTP command, to transfer files quickly. Do remember, WPEngine doesn’t give SSH access, so I need to ask their support team to decompress the compressed folder. Also, if you are on shared hosting like Bluehost, you can always enable SSH access, by login into your cPanel. Here is a video, showing the process of enabling SSH on Bluehost (cPanel hosting).

Before the migration, I compressed the WP-content folder into single file, as this will make the transfer easy. You can also consider compressing the entire root directory and transfer it to your new hosting. You can always use a SSH client like Putty for running the commands, or you can simply use Terminal on Mac OS, for the same.

Here is what the process will be like:

  • ssh into old hosting server
  • from old hosting server sFTP into new server
  • Use Put command to copy files from old server to new server

And, if you have never done this before, but have a technical background, you will love trying this out.

Transferring files from Old Hosting to New Hosting using SSH

Open Terminal or Putty on your Mac and ssh into your old hosting server

 ssh [email protected]

If your port is other than default port, use this command

ssh [email protected] -oPort=2200

Replace 2200, with the port your server uses for SSH access. Now, you can compress your entire public_html folder using following command: (WPback.tar.gz is the compressed file name, which I want for compression).

 tar -cvzf wpback.tar.gz public_html

Note: wpback.tar.gz will be the single compressed file of your public_html folder. Depending upon your file size, it may take couple of minutes to compress the folder. Once compression is done, we will sFTP to your new server from old server terminal.

On the same terminal, type

 sftp [email protected]

Type yes and enter your password to sFTP into your new hosting server from old server. You can use command:

  • ls – list all files
  • cd – change directory
  • mk – make new directory

In my case, I created a new directory with the name Test, and used

 cd Test

to change my default working directory.

Now, simply type

put wpback.tar.gz

and it will start transferring your backup file from old hosting to new hosting. This process is usually fast, and within minutes of time, you can transfer GB’s of data from one server to another. In my case, it took 12 minutes to sFTP 2Gb of data from old hosting server to new. Now, all we need to do is decompress the transferred file on new server. In my case, I asked WPEngine hosting support team to do it for me.

Hope this helps, and if you have any other tip to add in here, feel free to let me know via comments. If you find this tutorial useful, do share it on Facebook and Google plus.