Rsync over SSH path with spaces does not work with quotes

12,438

Solution 1

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

Solution 2

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.

Solution 3

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

Share:
12,438

Related videos on Youtube

AndrewMRiv
Author by

AndrewMRiv

Updated on September 18, 2022

Comments

  • AndrewMRiv
    AndrewMRiv over 1 year

    I am able to successfully RSYNC over SSH as long as the paths do not have spaces in them.

    When the path does have spaces, it does not work. I have tried slashes, quotes, and double quotes.

    When I use slashes, the output states that it is a success but I do not see any transferred files.

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

    When I use single or double quotes, it tells me that permission is denied after entering my password

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

    What can I do?

    Thank you.