To rsync a file or directory that contains spaces, you must escape both the remote shell and the local shell. I tried doing one or the other and it never worked. Now I know that I need to do both!
So lets say I’m trying to rsync a remote directory with my local machine and the remote directory contains a space (oh so unfortunately common with Windows files). Here’s what the command should look like:
rsync 'raam@example.com:/path/with\ spaces/' /local/path/
The single quotes are used to escape the space for my local shell and the backslash is used to escape the remote shell.

Thanks, very useful article!
You’re welcome, AaL! :)
Thanks – I’ve been trying to work out how to do this for months! It never occurred to me to escape both the local and remote paths.
No problem! Glad I could help!
or the rsync option –protect-args (-s), no slashes needed
rsync manual describes how the remote shell interprets all filenames and options. with –protect-args the filenames and options are interpreted by the remote rsync only.
no description in the manual how filenames and options are interpreted at the local shell by shell or rsync source sender. at least we know to write quoted filenames to rsync like most shell programs that read filenames with spaces.
an rsync transfer, minimally escaped
rsync -s andrew@example:/path/’path spaced’/ “/to/destination spaced/”
for filenames, notice that you could either quote the spaced part of a path only, or the path full. either escape form may single quote or double quote
That’s helpful info, Andrew! Thanks! :)
Thanks for the tip about –protect-args!
This saved me a whole lot of trouble since although what Raam Dev wrote is correct it’s impossible (or very difficult) to use in scripts where the path with spaces is in a variable.
Hello all,
pls help.
I need some help with rsync functionality for ‘files-from=’.
sorry there is impossible to post some lines of script, so there is link, where I try my luck too.
http://www.procata.com/blog/archives/2005/03/01/rsync-to-remote-server-via-ssh/#comment-85796
Hi Petr,
I’m not sure what the problem is but perhaps someone else who visits here will be able to help. Good luck!
I found it, probably black hole in old OS (was debian 3.1) today no problem in my 10.04 kubuntu with remote processing –file-from=list
Cheers !
Great! Thank you for the update, Petr! :)
Nice tip :)
[trolling] While there is no such thing as ‘God’ -as those mind control systems known as religions wants us believe-, and while every Mac user on earth is a faggot[/trolling] I find your About section somewhat interesting and that’s a lot for me; I’ve already bookmarked your site to read it on my free time.
Best
Haha, thanks and nice to meet you too. :)
Hi, what about handling spaces in all the files and subdirectories? Thanks.
That should already work for files and subdirectories.
Thanks! One of those things that shouldn’t be forgotten but often is.
You’re most welcome, Jeff! :)
Thanks for this!! – I’d been scratching my head RE this and your post came up on a google search!
Awesome! You’re welcome. Glad I could help out. :)
Cheers.