Files transfer using scp & rsync commands
Last updated on June 11th, 2018 at 03:14 pm
Hello Linux-fanatics, in this tutorial we will discuss how to transfer files among system using scp & rsync with some examples. (also read tutorial on “Cloning disks using dd & cat commands“). But firstly let’s discuss both commands in brief.
scp & rsync commands
scp is based on ssh & is used to transfer file from local host to remote host securely. Syntax for using scp is
Rsync’s main function, on the other hand is basically to synchronize files/directories either on local host or on remote host. Rsync initially copies whole directory & then copies newly added files (differential backup) rather than copying whole directory again.
It is secure & faster than scp & can also be used in place of scp command to copy files/directories to remote host. Syntax for using rsync is
Now, let us discuss some examples showing uses of both commands.
Examples for scp
here, option r is used when we are copying a directory with all the files inside it,
secondly option p will provide an estimate time & connection speed,
and option v will provide debugging information which can help in diagnosing a problem related to connection, authentication etc.
option C here will compress the file on the go & will reproduce the same file when it arrives at the destination. Thus saving time consumed for copying the file.
here option –P is used to define a custom port incase we are not using default ssh port (22).
Examples for Rsync
here, option r is archive mode which allows copying of files recursively along with their file permissions, symbolic links etc,
Second option r is used to compress file data,
third option h will provide human readable outputs,
and option v will provide debugging information which can help in diagnosing a problem related to connection, authentication etc,
Also, we can mention alocal location like /home/dan in place of email@example.com:/home/susan
above example will let us synchronize a directory from remote location to local host directory & –progress will show us the progress of file/directory transfer.
this example will let us use rsync over ssh and option –e here is used to define a protocol , which is this case is ssh.
here, this example will let us use rsync over ssh with modified port.
this will let us copy all files starting with “A” & will exclude all other files.
Both the scp & rsync can be used to transfer files/directories but rsync fares a little better when comes to performance. Also rysnc has option to take differential backup which scp lacks. But both are equally secure & very easy to use.
Don’t forget to leave your comments/queries in the comment box. ADIOS!!!