Suppose I use rsync in the following way:

rsync user@server:/path/to/file1 user@server:/path/to/file2 /local/directory

to copy file1 and file2 from a remote server to a local directory. Does rsync in this case establish two separate ssh-connections (one per file) to copy the two files or does it establish one ssh connection and keep it open as long as necessary?

migrated from stackoverflow.com Aug 25 '17 at 9:54

This question came from our site for professional and enthusiast programmers.

  • If you configure ssh to use ControlMaster/ControlSocket it'll be only one connection regardless (and would be only one connection even if you invoked rsync several times). – Charles Duffy Aug 24 '17 at 17:48
  • Are there now multiple ssh connections established in the case I mentioned? – Joerg Aug 24 '17 at 18:16

You can trivially test this yourself, which will give you an answer valid for the specific version of rsync in use:

rsync -e $'sh -x -c \'exec ssh "$@"\' _' \
  user@server:/path/to/file1 user@server:/path/to/file2 /local/directory

(Note that the $'' syntax used above is an extension available in ksh or bash, but not with /bin/sh).

You'll see a line logged by sh -x for each individual ssh command being run. If there's only one ssh command, then your specific version of rsync is capable of reusing the connection. (This appears to be the case in my own testing with version 3.1.2).

  • Thank you very much, that was exactly the kind of thing I was looking! I also use rsync version 3.1.2, which gives the result you wrote. – Joerg Aug 25 '17 at 9:17

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.