60

Is there a reason to use scp instead of rsync? I can see no reason for using scp ever again, rsync does everything that scp does, with more safety (can preserve symlinks etc).

  • 6
    Short answer: No. scp is never harmful. – Shadur May 31 '12 at 9:01
  • 2
    @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. – Gilles May 31 '12 at 22:46
  • 3
    @Gilles As with any tool, you must understand what it does and how it does it to use it safely. – Alex Chamberlain Jun 1 '12 at 7:24
  • 8
    In that context, regular cp and rm 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. – Shadur Jun 1 '12 at 9:31
  • 1
    On systems without rsync installed, using rsync is (obviously) not even possible. – Kusalananda Feb 21 '18 at 10:23
44

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.

  • 8
    Also, pretty sure rsync has to be installed on the other end. – ckhan May 31 '12 at 7:59
  • 3
    @ckhan, no it can copy without having anything installed in the other side, it'll just be less efficient. – mikebloch May 31 '12 at 8:40
  • 2
    I like scp's simplicity. – Alex Chamberlain May 31 '12 at 9:29
  • 2
    @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. – Alexios May 31 '12 at 10:00
  • 1
    @mikebloch, it has to be installed on the server to do the checksum computations, which can add a lot of cpu load to the server. This is why most large sites don't support it, and why zsync was created as an alternative. – psusi May 31 '12 at 22:17
17

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.

  • 3
    Might 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. – Flup Jul 26 '13 at 15:28
  • As @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. – Lester Cheung Mar 1 '16 at 10:56
  • Well, rsync -vP username@host:/path/to/file . will do this too. See this answer on Stackoverflow – Devesh Saini Aug 12 '16 at 18:20
8

rsync: Transfers deltas(using its Delta Transfer Algorithm) between:

  1. local and remote hosts

scp: Transfers whole files between:

  1. local and remote hosts
  2. remote and remote hosts

Summary: scp can transfer files between two remote hosts while rsync doesn't support it.

  • rsync can transfer files between two remote hosts. In fact, rsync a host:b is equivalent to scp a host:b. – brandizzi Feb 19 '17 at 13:34
  • That'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 – Devesh Saini Feb 19 '17 at 14:08
2

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 like scp, but for a second transfer, where most files are unchanged, it will push a lot less data than scp. 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, whereas scp will start again from scratch.

0

scp is simpler to use as it takes less arguments. I catch myselv using scp instead of rsync if I only transfer a single file. Propably I am just to lazy to define an alias to rsync... ;-)

  • 1
    Hmmm, why is it so? rsync a host:b is equivalent to scp a host:b, same number of arguments. – mikebloch Apr 9 '13 at 5:40
  • 1
    @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. – Nils Apr 9 '13 at 14:44
0

Credits to @tomrunia at https://gist.github.com/KartikTalwar/4393116

rsync -aHAXxv --numeric-ids --delete --progress \
  -e "ssh -T -c aes128-gcm@openssh.com -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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.