How does `scp` differ from `rsync`?
The major difference between these tools is how they copy files.
scp
basically reads the source file and writes it to the destination. It performs a plain linear copy, locally, or over a network.
rsync
also copies files locally or over a network. But it employs a special delta transfer algorithm and a few optimizations to make the operation a lot faster. Consider the call.
rsync A host:B
rsync
will check files sizes and modification timestamps of both A and B, and skip any further processing if they match.If the destination file B already exists, the delta transfer algorithm will make sure only differences between A and B are sent over the wire.
rsync
will write data to a temporary file T, and then replace the destination file B with T to make the update look "atomic" to processes that might be using B.
Another difference between them concerns invocation. rsync
has a plethora of command line options, allowing the user to fine tune its behavior. It supports complex filter rules, runs in batch mode, daemon mode, etc. scp
has only a few switches.
In summary, use scp
for your day to day tasks. Commands that you type once in a while on your interactive shell. It's simpler to use, and in those cases rsync
optimizations won't help much.
For recurring tasks, like cron
jobs, use rsync
. As mentioned, on multiple invocations it will take advantage of data already transferred, performing very quickly and saving on resources. It is an excellent tool to keep two directories synchronized over a network.
Also, when dealing with large files, use rsync
with the -P
option. If the transfer is interrupted, you can resume it where it stopped by reissuing the command. See Sid Kshatriya's answer.
Finally, note that rsync://
the protocol is similar to plain HTTP: unencrypted and no integrity checks. Be sure to always use rsync
via SSH (as in the examples from the question above), not via the rsync protocol, unless you really know what you're doing. scp
will always use SSH as underlying transport mechanism which has both integrity and confidentiality guarantees, so that is another difference between the two utilities.
rysnc can be useful to run on slow and unreliable connections. So if your download aborts in the middle of a large file rysnc will be able to continue from where it left off when invoked again.
Use rsync -vP username@host:/path/to/file .
The -P option preserves partially downloaded files and also shows progress.
As usual check man rsync