Rsync over SSH path with spaces does not work with quotes

You need to escape spaces in both local shell and remote shell. Try this:

rsync -avz '/path with spaces/' 'user@remotelocation:/media/another\ path\ with/spaces/'

The source, /path with spaces/ in the local shell can be escaped only via putting single quotes around it i.e. '/path with spaces/'.

On the other hand in case of the destination, the local shell is escaped by putting single quotes and the spaces are escaped in the remote shell by using escape character (\) in front of the spaces.


Expanding on rzr's answer with example code and references, just add the -s flag, quote the paths, and don't worry about escaping spaces in the remote path:

rsync -avzs '/path with spaces/' 'user@remotelocation:/media/another path with/spaces/'

For reference, the options specified by the OP:

  • -a, archive mode, equals -rlptgoD (no -H,-A,-X)
    • Includes:
    • -r, --recursive, recurse into directories
    • -l, --links, copy symlinks as symlinks
    • -p, --perms, preserve permissions
    • -t, --times, preserve modification times
    • -g, --group, preserve group
    • -o, --owner, preserve owner (super-user only)
    • -devices, preserve device files (super-user only)
    • -specials, preserve special files
  • -v, --verbose, increase verbosity
  • -z, --compress, compress file data during the transfer

The additional parameter needed:

  • -s, --protect-args, no space-splitting, wildcard chars only

look at rsync option –protect-args (-s), no extra slashes needed

Tags:

Ssh

Rsync