8

I want to copying multiple files from remote machine using rsync. So I use the following command.

rsync -Pav -e 'ssh -i sshkey' user@remotemachine:/home/user/file1.zip file2.zip file3.zip  .

It shows following error

Unexpected local arg:file2.zip If arg is a remote file/dir, prefix it with a colon (:). rsync error: syntax or usage error (code 1) at main.c(1362) [Receiver=3.1.0]

6

All remote files should be one argument for rsync. So, just put all remote files in single brackets:

rsync -Pav -e 'ssh -i sshkey' 'user@remotemachine:/home/user/file1.zip file2.zip file3.zip' .

BTW, you can also do this with a Asterisk (the Asterisk will be resolved by the remote shell then):

rsync -Pav -e 'ssh -i sshkey' 'user@remotemachine:/home/user/*.zip' .
  • 1
    It works Great Because of Alexander The Great – SuperKrish Sep 9 '16 at 11:07
3

This is pretty old, but the accepted answer is a bit too strict - multiple files are not necessarily a single argument to rsync. From man rsync:

ADVANCED USAGE
       The  syntax  for  requesting  multiple  files  from a remote host is done by specifying additional remote-host args in the same style as the first, or with the hostname omitted.  For
       instance, all these work:

              rsync -av host:file1 :file2 host:file{3,4} /dest/
              rsync -av host::modname/file{1,2} host::modname/file3 /dest/
              rsync -av host::modname/file1 ::modname/file{3,4}

so OP's command would be

rsync -Pav -e 'ssh -i sshkey' user@remotemachine:/home/user/file1.zip :/home/user/file2.zip :/home/user/file3.zip  .

This is not possible for older versions of rsync, but I think all major distros some with this for several years now.

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.