3

When trying to copy a file from Linux (Raspbian to be precise, though I don't think it matters) to Windows using SCP:

scp a.txt {user}@{ip}:\C\Users\{user}\a.txt

The file is copied, but to C:\Users\{user}\CUsers{user}a.txt.

It looks as if I need to escape the '\' somehow, but couldn't figure out how.

  • try forward slashes '/' i think it must be something like this: scp a.txt user@ip:/C\:/Users/user/a.txt but I am not sure about how to handle the C-drive with the ':' character – syss Mar 11 '16 at 9:12
  • Which sshd product is in use on the Windows machine? – EightBitTony Mar 11 '16 at 9:55
3

While I have never used scp on Windows, so I am only guessing, it certainly looks like the backslashes are ignored. Or, rather, as if they are taken as escape characters and, since they don't escape anything relevant, are being ignored. Consider this, on a Linux machine:

$ cd \usr\share
bash: cd: usrshare: No such file or directory

As you can see, the \ were ignored and the path concatenated to a single string, just like what you describe above.

The default target location for scp is the user's home directory. Since that is \C\Users\userName, your attempt to specify a path is taken for a file name (\C\Users\userName\a.txt becomes CUsersuserNamea.txt) and the file is saved in the default location with that name: C:\Users\userName\CUsersuserNamea.txt.

A simple solution, in this case, would be to not specify a path:

scp a.txt user@ip:
  • 1
    Thanks, by combining your answer with @syss comment I've managed to get it working. For future reference, scp user@ip:\C:/path/with/forward/slashes does the trick. – DeepSpace Mar 11 '16 at 9:36
  • @DeepSpace really? That's surprising. Did you also try scp user@ip:/C:/path/with/forward/slashes? With no `` at all? – terdon Mar 11 '16 at 9:48
  • 1
    This is 100% due to the shell on the sending machine. scp is receiving scp a.txt {user}@{ip}:CUsers{user}a.txt as its arguments - it's never even seeing the backslashes. – Andrew Medico Mar 11 '16 at 14:17
2

When playing with Windows paths, I would recommend to use relative one, such as (relative to home directory):

scp a.txt {user}@{ip}:a.txt

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.