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

IN Webhosting

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

Copy Files 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 ShoutMeLoud 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 username@hostname

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

ssh username@hostname -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).

Compressing directory to single file

 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

sftp one server to another

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.

Click to activate Offer & visit site Discount added automatically

Ultimate Blogging Strategies

Sign Up Today For Free

join our site and get free content delivered automatically each time we publish

100% privacy. we will never spam you

Watch More Related Vidoes

  • Author Bio

  • Latest Post

Article by Harsh Agrawal

Harsh has written 1047 articles.

If you like This post, you can follow ShoutMeLoud on Twitter. Subscribe to ShoutMeLoud feed via RSS or EMAIL to receive instant updates.

Send Us Inquiry


  1. Damanjit Singh says

    Very good tutorial Harsh!
    Your guide is really helpful specially for those who have slow internet connection (like in India). I’ve few questions:

    Do you prefer to have a control panel in your VPS (like Cpanel)? Or you like to manage your VPS via SSH?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>