SSH scp: Escaping Spaces and Encapsulation

Here is an interesting little tidbit of ssh goodness that I’ll never remember unless I write it down here…

When using ssh scp to recursively copy directories with spaces in their name, you will get the error `scp: ambiguous target` even if you escape the spaces. For example, this will fail:

scp -r ~/Movies/Doctor Who adam@fileserver:/Movies/Doctor Who

However, if you use **both** back slash escapes *and* double quotes after the colon then scp will work just fine. Like so:

scp -r ~/Movies/Doctor Who adam@fileserver:"/Movies/Doctor Who"

So now you know.

 

Adam Merrifield

 

Leave a Reply