Copying multiple files from remote using rsync over ssh

command linersync

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]

Best Answer

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

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' .
Related Question