Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

scp from remote Linux to local Windows with spaces in local path

Writer Matthew Barrera

To push a file from a Linux terminal to a Windows system, the following two examples work just fine.

scp /home/ :/C:/Users/
scp /home/ :"/C:/Users/"

I need to do this where the local folder has spaces and I cannot change the name, say /C:/Users/ folder/

All of the following fail with the message scp: ambiguous target

scp /home/ :"/C:/Users/ folder/file.html"
scp /home/ :"/C:/Users/ folder/file.html"
scp /home/ :"'/C:/Users/ folder/file.html'"
scp /home/ :"/C:/Users/ folder/file.html"
scp /home/ :"'/C:/Users/ folder/file.html'"
scp /home/ :"/C:/Users/ folder/file.html"
scp /home/ :"'/C:/Users/ folder/file.html'"

How do I get this to work?

2

5 Answers

  • Try using quotes ' or Double quotes " around complete argument.

    As suggested by @dirkt in comments Quoting the complete path argument for the ssh host should do the work. That makes your command like this :

    scp /home/ ':/C:/Users/ folder/'
  • Use escape sequence for space in between name of folder.

    You can use \ (backslash with a space) that is escape sequence for a space. That makes your command like this :

    scp /home/ ':/C:/Users/ folder/'

    Notice the \ with a space in between test & folder that makes it test\ folder.

  • It maybe the case that you need to escape twice as It is escaped first locally and then on the remote end. In that case you can write like this :

    1. "'complete argument'" inside quotes within double quotes like this :

      "':/C:/Users/ folder/'"

      OR

    2. Escape spaces and quote complete argument like this :

      ':/C:/Users/ folder/'

      OR

    3. Escape twice directly using escape sequence like this

      :/C:/Users/ folder/

Feel free to add-in more details.

2

Tried all the options above to scp from CentOS client to Windows 7 (SP1), but without success.

This one worked for me though:

$ scp /tmp/lala 'win7@<IP>:"/Users/win7/Documents/TestComplete 14 Projects"'
1

The " symbol is interpreted by bash itself. Bash decapsulates anything in between interbretes if it can and just presents the outout to a command being called as a string that may have some special symbols. Try using the apostrophe (') symbol for it forces bash not to look at the string at all and just pass it to a command that was invoked first. Those strings with ' should be formatted like this: If you want to see

don't

echo $'dont\'t'

I don't know if this is still relevant, but one solution (that might backfire in some situations) is using "?" instead of space:

scp "user@ip:/home/user/file?with?spaces.txt" .

Well, one more possible solution is just use Git Bash or any other bash emulator.

Then just escape all spaces with \ before each and wrap statemens with double quotes.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy