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

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended. Read more about Affiliate disclosure here.

Copy Files One Server to Another Using SSH Command
  • Save

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 [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).

Compressing directory to single file
  • Save

 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
  • Save

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.

Subscribe on YouTube

  • Save
Authored By
A Blogger, Author and a speaker! Harsh Agrawal is recognized as a leader in digital marketing and FinTech space. Fountainhead of ShoutMeLoud, and a Speaker at ASW, Hero Mindmine, Inorbit, IBM, India blockchain summit. Also, an award-winning blogger.

10 thoughts on “How to Copy Files from One Server to Another using SSH Command”

  1. Damanjit Singh

    Very good tutorial Harsh!
    Your guide is really helpful especially 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?

  2. How about if you want to transfer a folder with large total size, like 100GB, from 1 VPS to another VPS?

  3. Apoorv Agrawal

    Bro It’s sad to say this tutorial is not really helpful I got rid of searching all over the web thought you would have provided a detailed guide but sadly its not really helpful.

    If its possible for you to edit can you just make it from the starting how to move from one hosting to another via ssh?? everything how putty is used and with clear images that could ease.

Leave a Comment

Your email address will not be published.

Scroll to Top
Share via
Copy link