SCP a path with spaces from one machine to other

When you are coping a directory from one machine to other its not a problem usually. But when the path contains spaces in it then you need to escape the space.

Copping a path with space:

scp -r user_name@server_ip:"path/of/directory\\ name" .

Here -r stands for recursive copy of the folder from server to local system. The spaces need to be double escaped as the first escape only signifies that they’re spaces on the LOCAL machine, by the time they got to the remote machine, they wouldn’t be escaped anymore. By double escaping them locally, by the time the path makes it to the remote machine they are just single escaped.

comments powered by Disqus