11

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?

Thanks!

4
  • Hi, and welcome to SU. Answering your own questions is not only OK, but actively encouraged on the Stack Exchange network. Please edit your question to make it into a real question and then post your solution as an answer and accept it.
    – terdon
    Apr 14, 2013 at 20:00
  • 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! Apr 14, 2013 at 20:05
  • Welcome to SU. Your answer is correct but in a comment. The best you can do is to copy it to the answer section and accept it as correct. This way it can be upvoted so you earn reputation and people with the same problem will have an indication that your answer works and how many people found it helpful.
    – laurent
    Apr 14, 2013 at 20:31
  • Afte terdon comment, I triend to Answer my own question, but I was not allowed: I had to wait 8 hours to do it because I am a new user. Apr 15, 2013 at 6:32

4 Answers 4

15

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

1

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.

3
  • Technically, those a single quotes, not apostrophes. It's the same character in ASCII, but the term apostrophe has English grammatical implications that don't apply here.
    – depquid
    Apr 14, 2013 at 20:53
  • Thanks, I was going to call it a quote but didn't want to cause any confusion. I'll remember "single quote" next time.
    – user183714
    Apr 14, 2013 at 20:54
  • 1
    I am sorry, that is not working. It is necessary to combine single quotes with backslashes or double quotes. Tab did not work for me either. Apr 15, 2013 at 6:33
0

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 protected]:"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.

-1

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$

or

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..

1
  • Why your post might answer the question please explain how it works and why it's different from the previous answers. May 29, 2017 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .