Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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).

share|improve this question
5  
Short answer: No. scp is never harmful. –  Shadur May 31 '12 at 9:01
    
@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
    
@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
2  
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
    
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. –  mikebloch Jun 10 '12 at 12:09
add comment

5 Answers

up vote 3 down vote accepted

If you have to copy a large number of files, or have large files, rsync over ssh will be much faster than scp.

share|improve this answer
    
rsync speeds up copies when the destination already has an older copy of the file(s) by sending only the changed parts, otherwise it is not faster than scp. –  psusi May 31 '12 at 22:19
1  
You can try it out yourself, or take someone elses word for it: digitalsanctuary.com/tech-blog/debian/… . Try scp vs rsync of your /usr/bin/ dir for example. –  Not Now May 31 '12 at 22:43
    
@psusi Rsync does have less per-file overhead than scp from OpenSSH, so it's faster when copying many small files, even for a brand-new copy. –  Gilles May 31 '12 at 22:48
1  
It looks like scp does have a problem with large numbers of small files. With a single large file though, both can easily saturate a 100 mbps lan. –  psusi Jun 1 '12 at 14:32
1  
Interesting. rsync should have more overhead, since it needs to check in advance if the target(s) exists. –  Nils Jun 10 '12 at 20:56
show 1 more comment

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.

share|improve this answer
3  
Also, pretty sure rsync has to be installed on the other end. –  ckhan May 31 '12 at 7:59
    
@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
    
@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) –  mikebloch May 31 '12 at 8:41
1  
@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
show 2 more comments

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.

share|improve this answer
    
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
add comment

The bottom line, try to use rsync all the time. The details follow.

Use scp if you want to strictly populate the destination.

Use rsync if you want to have the choice between strictly populating the destination or populating-and-deleting-at the destination. When you deploy a system the --delete option ensures a clean deployment.

Suppose there is a folder a/empty and no such file as a/empty/file

Suppose there is a folder b/empty and also a file as b/empty/file, in other words, contrary to the appearance, it is not empty.

Contrast the following:

scp -r a/* b

rsync --delete --recursive a/* b.

In the case of rsync, the folder of the same name will be emptied. Of course, for both commands, whatever is caught by the wildcard, *, will cloned anew at the destination.

In order to minimize human error caused by lack of familiarity, just use rsync all the time, omitting the --delete option when you want behaviour like that of scp. rsync looks complicated, so use a script to constrain functionality, hopefully severely.

Here's one.

#!/bin/bash

# Presently, this script is named deploy.sh.
#
# It uses rsync, secured, to do something like a push scp.  
# Unlike scp files will be deleted at the destination.
# 
# RECOMMENDATION: To minimize risk, always use this script instead of
# invoking rsync directly for push operations.  
# Pulling via rsync seems less risky so I do not have a rsync wrapper for pulling.

SCRIPTNAME=$(basename $0)
if [ $SCRIPTNAME != "deploy.sh" ]
then
  printf "Are you sure this script is well named?\n"
  exit 0
fi

usage() {
  printf "usage:\n"
  printf "deploy.sh sourceFolder /path/destinationFolder [recursive]\n"
  printf "The destination path must be absolute.\n"
  printf "The sourceFolder must have the same name as the destinationFolder.\n"
  printf "You need to define an EV like this DESTINATIONIP=255.255.255.255.\n"
}

syncMethod1() {
  rsync --delete $3 --compress --progress \
    --times --perms --owner --group \
    --rsh="ssh" \
    "$1"/ root@$DESTINATIONIP:"$2"     
  # note the trailing slash on the source
  # note to use --delete you must omit the * at the end of the source
}

syncMethod0() {
  BASENAMESOURCE=$(basename $1)
  BASENAMEDESTINATION=$(basename $2)
  if [ $BASENAMESOURCE = $BASENAMEDESTINATION ]
  then
    syncMethod1 $1 $2 $3
  else
    usage
    printf "\nThe two folders must have the same name.\n"
  fi
}

FIRST=$1
SECOND=$2
THIRD=$3

if [ ! -d "$FIRST" ]
then
  usage
  printf "\nThe source must be a folder.\n"
elif [ $# != 2 ] && [ $# != 3 ]
then
  usage
  printf "\nWrong number of arguments.\n"
elif [ -z $DESTINATIONIP ]
then
  usage
  printf "\nUndefined DESTINATIONIP.\n"
elif [ ${SECOND:0:1} != "/" ]
then
  usage
  printf "\nDestination path error.\n"
else
  if [ $# = 2 ]
  then
    RECURSIONOPTION="--dirs"     # shallow
    syncMethod0 $FIRST $SECOND $RECURSIONOPTION
  elif [ $# = 3 ]
  then
    if [ "$THIRD" = "recursive" ]
    then
      RECURSIONOPTION="--recursive"
      syncMethod0 $FIRST $SECOND $RECURSIONOPTION
    else
      usage
      printf "\nUnknown parameter.\n"
    fi
  fi
fi
exit 0
share|improve this answer
add comment

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... ;-)

share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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