SCP Escape Syntax
Secure copying files with shell metacharacters embedded in their names involves slightly more arcane escaping syntax than usual. Imagine the following file:
$ scp yuki@192.168.0.61:hello world .
scp: hello: No such file or directory
cp: cannot stat 'world': No such file or directory
Well duh, you’ve got to escape that space in the middle of the name.
$ scp yuki@192.168.0.61:hello\ world .
scp: hello: No such file or directory
scp: world: No such file or directory.
Hang on. Maybe quote it?
$ scp yuki@192.168.0.61:"hello world" .
scp: hello: No such file or directory
scp: world: No such file or directory
Well single quotes are the strongest type of quote.
$ scp yuki@192.168.0.61:'hello world' .
scp: hello: No such file or directory
scp: world: No such file or directory
Boo.
It turns out that the filename needs to be either escaped AND quoted or simply quoted twice.
Any of the following will work.
$ scp yuki@192.168.0.61:'hello\ world' .
$ scp yuki@192.168.0.61:"hello\ world" .
$ scp yuki@192.168.0.61:"'hello world'" .
$ scp yuki@192.168.0.61:'"hello world"' .
$ scp yuki@192.168.0.61:"\"hello world\"" .