I have in a remote
remote_host a file like this:
\home\user\path with spaces\filename with spaces.ext
And I want to
scp it to current dir
.. How can I do that?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
After some investigation, I have found these two options:
scp 'user@remote_host:"/home/user/path with spaces/filename with spaces.ext"' .
scp 'user@remote_host:/home/user/path\ with\ spaces/filename\ with\ spaces.ext' .
I hope it helps you too!
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
You have two options.
Option one: enter spaces as "\ ". Example;
/home/matthew/File\ With\ Spaces.file.
Option two: enter the path in
apostrophes single quotes like so:
'/home/matthew/File With Spaces.file'.
If you use tabulator key (Tab) to auto-complete the file name, it will insert "\ " automatically, however you need to be using public key authentication for it to work on a remote host.
For me, copying from remote windows host (windows 10) to local Centos 8 machine through scp: putting ? in place of space and full path with quotes worked: example: scp email@example.com:"d:/downloads/sample?data/Copy?.csv" . (the last . is for current directory on linux). I had path with spaces and multiple csv files also with spaces on windows machine so used Copy? as can be seen above.
Try this my friend..
defstr PathAndFileName$ defstr Sheller$ PathAndFileName$="'c:\Documents And Settings\Users\Desktop\File.ext'" Sheller$="scp 'user@remote_host:PathAndFileName$'" Shell Sheller$
run "scp user@remote_host:PathAndFileName$"
you must put any path or filenames in quotes or scp treats anything after space as an option or command..