Use rsync to transfer files

In this article I’m going to teach you how you can utilize the Linux rsync command on either your VPS (Virtual Private Server) or dedicated server to transfer files remotely from another server that you have SSH access to.

It’s very common that you might need to transfer a large volume of files from a remote server to your server with InMotion Hosting, in these cases it can be time consuming to first download all of the files from your remote server to your local computer, and then uploading them again to your server with InMotion.

You can skip this process altogether in most cases by simply connecting to your server first via SSH, then using the rsync command you can simply pull files from the other remote server directly onto the server.

Please note that you might have to add your server’s IP address to the firewall of the remote server to allow the rsync connection, in this example I’m going to simply temporarily flush the firewall rules so that the connection is allowed.

Using rsync to transfer files

Using the steps below I’ll walk you through connecting to your server with InMotion Hosting and using the rsync command to transfer over some files from another remote server.

  1. Login to your server via SSH.
  2. Navigate to the directory you’d like to transfer files to with the following command:

    cd /home/userna5/public_html/

  3. Next run the following command to establish a rsync connection to a remote server, and copy over the entire /home/username/public_html/wordpress directory to the current /home/userna5/public_html/ directory.

    rsync -avzP [email protected]:/home/username/public_html/wordpress ./

    The -a flag is for archive mode which automatically enables other features which causes rsync to work in a backup up files manner. The -v flag is for verbose information, so that you see what files are in the process of being uploaded. The -z flag tells rsync to compress files during the transfer to save on transfer time. Finally the -P flag shows the total progress of what’s been transferred so far.

    Now in this case it just sits there and hangs, this is because of the remote server’s firewall not allowing the rsync connection, and it’s timing out. So I ran the following command on that remote server to temporarily flush the firewall rules and allow the new connection:

    apf -f

    This should display back something like this:

    apf(21697): {glob} flushing & zeroing chain policies
    apf(21697): {glob} firewall offline

    Now go ahead back to your server with InMotion Hosting and run the rsync command again, this time it shouldn’t timeout and you should see something similar to:

    The authenticity of host ‘example.com (123.123.123.123)’ can’t be established.
    RSA key fingerprint is 31:ec:1b:8e:35:b9:29:7b:80:88:11:14:52:c9:85:3b.
    Are you sure you want to continue connecting (yes/no)?

    Type in yes to allow the connection, then hit Enter.

    You should then get back:

    Warning: Permanently added ‘example.com,123.123.123.123’ (RSA) to the list of known hosts.
    [email protected]’s password:

    So go ahead and type in your remote server’s username’s password, and the transfer process should begin. When it completes you should see something like this:

    wordpress/wp-includes/theme-compat/header.php
    1723 100% 1.72kB/s 0:00:00 (xfer#1268, to-check=1/1407)
    wordpress/wp-includes/theme-compat/sidebar.php
    3904 100% 3.91kB/s 0:00:00 (xfer#1269, to-check=0/1407)

    sent 24674 bytes received 7732476 bytes 1034286.67 bytes/sec
    total size is 16462778 speedup is 2.12

  4. Now you’ll want to chown the files you just transferred over so that they have proper permissions with the following command:

    chown userna5.userna5 /home/userna5/public_html/wordpress/ -R

  5. Finally you should be able to take a look on your server and see that the files were all transferred over successfully:

    ll /home/userna5/public_html/wordpress

    Which in this case gives back all of the WordPress files we just transferred over remotely:

    -rw-r–r– 1 userna5 userna5 395 Jan 31 14:02 index.php
    -rw-r–r– 1 userna5 userna5 19929 Jan 31 14:02 license.txt
    -rw-r–r– 1 userna5 userna5 9177 Jan 31 14:02 readme.html
    -rw-r–r– 1 userna5 userna5 4663 Jan 31 14:02 wp-activate.php
    drwxr-xr-x 9 userna5 userna5 4096 Jan 31 14:02 wp-admin
    -rw-r–r– 1 userna5 userna5 1354 May 13 2012 wp-app.php
    -rw-r–r– 1 userna5 userna5 271 Jan 31 14:02 wp-blog-header.php
    -rw-r–r– 1 userna5 userna5 3522 Jan 31 14:02 wp-comments-post.php
    -rw-r–r– 1 userna5 userna5 3440 Feb 1 14:53 wp-config.php
    -rw-r–r– 1 userna5 userna5 3177 Jan 31 14:02 wp-config-sample.php
    drwxrwxr-x 7 userna5 userna5 4096 Feb 1 14:17 wp-content
    -rw-r–r– 1 userna5 userna5 2718 Jan 31 14:02 wp-cron.php
    drwxr-xr-x 9 userna5 userna5 4096 Jan 31 14:02 wp-includes
    -rw-r–r– 1 userna5 userna5 1997 Jan 31 14:02 wp-links-opml.php
    -rw-r–r– 1 userna5 userna5 2408 Jan 31 14:02 wp-load.php
    -rw-r–r– 1 userna5 userna5 29310 Jan 31 14:02 wp-login.php
    -rw-r–r– 1 userna5 userna5 7723 Jan 31 14:02 wp-mail.php
    -rw-r–r– 1 userna5 userna5 9899 Jan 31 14:02 wp-settings.php
    -rw-r–r– 1 userna5 userna5 18219 Jan 31 14:02 wp-signup.php
    -rw-r–r– 1 userna5 userna5 3700 Jan 31 14:02 wp-trackback.php
    -rw-r–r– 1 userna5 userna5 2719 Jan 31 14:02 xmlrpc.php

You should now understand how you can use the rsync command on your server in order to transfer over files from another server that you have access to.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+