How can I scp when path and / or filename to copy has spaces?

After some investigation, I have found these two options:

scp 'user@remote_host:"/home/user/path with spaces/filename with spaces.ext"' .

and

scp 'user@remote_host:/home/user/path\ with\ spaces/filename\ with\ spaces.ext' .

I hope it helps you too!

Have fun!

Edit - openssh was updated with a security feature that causes, with certain characters in the path name, an error message "protocol error: filename does not match request". In that case using scp's new -T option will allow it to work. for example

scp -T 'user@remote_host:"/home/user/path with spaces/filename with spaces and (2018).ext"' .

This is explained in https://stackoverflow.com/a/54599326

Tags:

Scp

Filenames