Is there ever a reason to use scp instead of rsync?
Solution 1
scp provides a cp like method to copy files from one machine to a remote machine over a secure SSH connection.
rsync allows you to syncronise remote folders.
They are different programs and both have their uses. scp is always secure, whereas rsync must travel over SSH to be secure.
Solution 2
One of the main things (which I think no one mentioned) is that if you are transferring large amounts of data or files, and if the transfer is disconnected before completion for any reason, rsync will pick it up where it left off. Whereas scp doesn't.
I use scp if I want to transfer one or couple of files or directories. I go to rsync for multi GB size data.
Solution 3
rsync: Transfers deltas(using its Delta Transfer Algorithm) between:
- local and remote hosts
scp: Transfers whole files between:
- local and remote hosts
- remote and remote hosts
Summary: scp
can transfer files between two remote hosts while rsync
doesn't support it.
Solution 4
User Chris at Webhosting Talk writes:
rsync
compares the files at each end and transfers only the changed parts of changed files. When you transfer files the first timeo it behaves pretty much likescp
, but for a second transfer, where most files are unchanged, it will push a lot less data thanscp
. It's also a convenient way to restart failed transfers - you just reissue the same command and it will pick up where it left off the time before, whereasscp
will start again from scratch.
Solution 5
Credits to @tomrunia at https://gist.github.com/KartikTalwar/4393116
rsync -aHAXxv --numeric-ids --delete --progress \
-e "ssh -T -c [email protected] -o Compression=no -x" \
[source_directory] user@hostname:[target_directory]/
Pay attention to --delete
, don't use it if you want to keep extraneous files in dest dirs
Comments
-
mikebloch over 1 year
Is there a reason to use
scp
instead ofrsync
? I can see no reason for usingscp
ever again,rsync
does everything thatscp
does, with more safety (can preserve symlinks etc).-
Shadur almost 12 yearsShort answer: No. scp is never harmful.
-
Gilles 'SO- stop being evil' almost 12 years@Shadur scp is harmful in that it overwrites existing target files by default. So's rsync, but it at least allows limiting the possible damage with
-u
. -
Alex Chamberlain almost 12 years@Gilles As with any tool, you must understand what it does and how it does it to use it safely.
-
Shadur almost 12 yearsIn that context, regular
cp
andrm
would be considered "harmful" -- and if you define "harmful" as "can screw me over if I do something stupid",rsync
isn't any less harmful. -
mikebloch almost 12 years
scp -a
will not work, and will be slower. I see no reason to use it, if you have something else at hand. rsync is less harmfull in the sense that it can at least preserve symlinks, so can cp. -
Gert van den Berg over 8 yearsThe other combination that I sometimes use, mostly with lots of small files, is
ssh user@source "cd /source/dir; tar -cf - stuff i want to send" | { cd /dest/dir; tar -xf -; }
. (Sometimes adding a gzip (mostly -1, I tend to do it over LAN connections) to the pipeline, depending on the data). It mainly handles large amount of small files better than most methods, if you have a reliable connection. -
Kusalananda about 6 yearsOn systems without
rsync
installed, usingrsync
is (obviously) not even possible.
-
-
evanda almost 12 yearsAlso, pretty sure rsync has to be installed on the other end.
-
mikebloch almost 12 years@ckhan, no it can copy without having anything installed in the other side, it'll just be less efficient.
-
mikebloch almost 12 years@Alex so the answer is: "scp ensures that you will always encrypt the data on the wire, rsync doesn't" (the fact that rsync has more features doesn't mean it can't be used as a mere cp)
-
Alex Chamberlain almost 12 yearsI like scp's simplicity.
-
Simon Gates almost 12 years@mikebloch How do you do that? Is it a new feature? Just tried this using version 3.0.9. and it complained it couldn't find
rsync
on the remote. -
mikebloch almost 12 years@AlexChamberlain why is scp simpler than rsync? (and the point that you have to have rsync on server is a valid point).
-
mikebloch about 11 yearsHmmm, why is it so?
rsync a host:b
is equivalent toscp a host:b
, same number of arguments. -
Nils about 11 years@mikebloch Two letters more to type... ;-) In the past I had to supply "-e ssh -a" to get the proper result. Now that "-e ssh" is default this might be a different game.
-
iTag almost 11 yearsMight be worth adding that the
--partial
flag is useful when transferring large files.rsync
will pick up where it left off within the file rather than starting that file again. -
Lester Cheung about 8 yearsAs @Flup mentioned rsync won't leave anyt file-in-transit around for you to resume unless you use the --partial option. These files are by default hidden in the target directory. You can use --partial-dir to put all of these files in a single directory.
-
Devesh Saini almost 8 yearsWell,
rsync -vP username@host:/path/to/file .
will do this too. See this answer on Stackoverflow -
brandizzi about 7 yearsrsync can transfer files between two remote hosts. In fact,
rsync a host:b
is equivalent toscp a host:b
. -
Devesh Saini about 7 yearsThat's what I wrote, rsync can transfer deltas between local and remote hosts but scp is not limited to just that, it can transfer deltas between two remote hosts. @brandizzi
-
Błażej Michalik over 5 years
scp
will run over SSH just asrsync
does. In fact, the only thingscp
on the client side does is it runsscp
with-f
/-t
flags on the remote via SSHexec_command
channel, and writes / reads the stream that is provided as stdin / stdout. So the third paragraph of this answer does not contribute anything here.