TAGS

There are no tags associated with this article.

How to upload and synchronize files with SCP / RSYNC?

SCP and rsync are capable of copying and sychronizing our files between separate locations. Although their destination in achieving the goal is the same, their techniques and concepts differs a little bit.

Let's introduce both of them:

  • SCP (secure copy) Its concept is to read the source file and assign the full plain linear copy to the destination place: locally or through the network. It is based on ssh.

  • RSYNC is also responsible for copying files locally or over the network as scp stated above. But moreover it implements some special algorithm to synchronize the data. As you may realize, it does not copy whole directory. It detects changes and redirect them to the destination source.

 

Syntax:

SCP:

 

scp [options] [source] [destination]

 

Basic example:

scp home/test/file1 eouser@185.178.13.12:/home/eouser/

 

 

Quick explanation:

  1. home/test/file1 is the source file

  2. eouser is a hostname of the server

  3. 185.178.13.12 is a ip address of the remote server

  4. home/eouser/ is the destination folder

 

Output:

file1 100% 230 43.6KB/s 00:00

 

Useful parameters:

 

-r It is mainly used for copying folders. Its goal is to Recursively copy entire directories.

 

-P port
Specifies the port to connect to on the remote host.

 

-c cipher
Selects the cipher to use for encrypting the data transfer.

 

-C' Compression enable.

 

-------------------------

Attention !

-i identity_file

This option is necessary when we does not use default files for authenticating ssh connection (id_rsa)

-------------------------

 

Syntax:

Rsync:

 

rsync [options] [source] [destination]

 

Basic example:

rsync -avz –progress -e "ssh -i /home/account/.ssh/id_rsa" file1 eouser@185.178.85.28:/home/eouser/

 

Output:

sending incremental file list
file1

sent 135 bytes  received 35 bytes  113.33 bytes/sec
total size is 57  speedup is 0.3

 

Additional explanations:

-progress bar is reponsible for giving results presented above.

As you can see I had to add my private ssh key for authentication with e parameter. There’s the case if we are not interested in sharing different passwords for both protocols.

 

Useful parameters:

  • v : verbose

  • r : copies data recursively (be cautious, it does not transduce permission while transferring data)

  • a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps

  • z : compress file data

  • h : human-readable, output numbers in a human-readable format