102

I try to transfer a folder of files from my local computer to a server via ssh and scp. After getting sudo privileges, I'm using the command as follows:

scp -r C:/desktop/myfolder/deployments/ user@host:/path/to/whereyouwant/thefile

However, I get the following error:

ssh: C: Name or service not known

I'm guessing it is due to my syntax for C:/desktop etc. Any ideas?

BTW I'm using putty + Windows 7.

tkazik
  • 919
  • 3
  • 12
  • 27
HelloWorld
  • 4,251
  • 8
  • 36
  • 60
  • 2
    The standard path on windows/dos says to use \ backslash, so try C:\desktop\myfolder\deployments\ – Cornel Ghiban Jan 23 '12 at 17:31
  • 2
    None of the non-GUI solutions work for me. I get the error, fork: No such file or directory. I can `ssh` the destination and I can `dir` to the source. – motorbaby Jun 14 '19 at 20:16

7 Answers7

92

If your drive letter is C, you should be able to use

scp -r \desktop\myfolder\deployments\ user@host:/path/to/whereyouwant/thefile

without drive letter and backslashes instead of forward slashes.

You are using putty, so you can use pscp. It is better adapted to Windows.

Serkan Yilmaz
  • 1,338
  • 19
  • 21
  • scp -r root@31.222.168.64:/var/www/vhosts/mywork \test --- I added this code this is create a test folder in my server no in my local computer scp -r root@31.222.168.64:/var/www/vhosts/mywork D:\test ---gives error "ssh: Could not resolve hostname D: Name or service not known lost connection" – pTi Mar 26 '16 at 17:31
  • @pTi which `scp` are you using? If you are using Cygwin's `scp`, you can use the path as `/cygdrive/d/test`. To omit using `/cygdrive` you can run `mount --change-cygdrive-prefix /` so that the path would be `/d/test` instead. – Serkan Yilmaz Jun 08 '16 at 20:40
  • Not sure if it's specific to tunneling or to the version of scp in Windows 10, but I had to use the syntax (after lots of trials and errors): scp -P -r ./localdir user@host:"D:\remotedir" – serigado Jun 11 '20 at 16:16
33

Drive letters can be used in the target like

scp some_file user@host:/c/temp

where c is the drive letter. It's treated like a directory.

Maybe this works on the source, too.

Jason
  • 11,709
  • 9
  • 66
  • 82
  • 14
    Thanks for this *simple* and *working* answer, not trying to make me use another software or whatever ! I was searching the web to find just that, nobody answers the question directly... – Benj Jul 02 '15 at 08:10
  • 1
    this does not work to get the files – Jorge Machado May 18 '17 at 06:02
  • 6
    In my case, `user@host:/` is the root for my `C:\ ` directory. So if I write `user@host:/temp/`, it is equivalent to `C:\temp\ `. I only have access to my `C` Drive, not others. – imans77 May 06 '19 at 07:49
  • 2
    @imans77, that may work, but if your drive letter is `e:` it won't ;-) That was the case for me and how I discovered this. – Jason May 20 '19 at 16:47
  • Using the stock 'scp' from a recent Windows Server 2022 version I was able to use the command from this answer above, but with using a colon in the drive specifier, as the first path segment on the target Windows machine: `scp some_file user@host:/C:/TEMP` – jaguild Aug 09 '23 at 00:12
22

On windows you can use a graphic interface of scp using winSCP. A nice free software that implements SFTP protocol.

jedi
  • 839
  • 12
  • 33
10

I see this post is very old, but in my search for an answer to this very question, I was unable to unearth a solution from the vast internet super highway. I, therefore, hope I can contribute and help someone as they too find themselves stumbling for an answer. This simple, natural question does not seem to be documented anywhere.

On Windows 10 Pro connecting to Windows 10 Pro, both running OpenSSH (Windows version 7.7p1, LibreSSL 2.6.5), I was able to find a solution by trial and error. Though surprisingly simple, it took a while. I found the required syntax to be

BY EXAMPLE INSTEAD OF MORE OBSCURE AND INCOMPLETE TEMPLATES:

Transferring securely from a remote system to your local system:

scp user@remotehost:\D\mySrcCode\ProjectFooBar\somefile.cpp C:\myRepo\ProjectFooBar

or going the other way around:

scp C:\myRepo\ProjectFooBar\somefile.cpp user@remotehost:\D\mySrcCode\ProjectFooBar

I also found that if spaces are in the path, the quotations should begin following the remote host name:

scp user@remotehost:"\D\My Long Folder Name\somefile.cpp" C:\myRepo\SimplerNamerBro

Also, for your particular case, I echo what Cornel says:

On Windows, use backslash, at least at conventional command console.

Kind Regards. RocketCityElectromagnetics

Stevy
  • 3,228
  • 7
  • 22
  • 38
Charles
  • 338
  • 3
  • 8
1

You can also try this:

scp -r /cygdrive/c/desktop/myfolder/deployments/ user@host:/path/to/whereyouwant/thefile
Aditya
  • 1,693
  • 19
  • 27
  • 3
    This answer will only work if you have cygwin installed and you are running in a cygwin shell or using a cygwin executable. But this is a valid answer that will work for some people. – Jason Jul 14 '15 at 23:31
-2

I have found it easiest to use a graphical interface on windows (I recommend mobaXTerm it has ssh, scp, ftp, remote desktop, and many more) but if you are set on command line I would recommend cd'ing into the directory with the source folder then
scp -r yourFolder username@server:/path/to/dir
the -r indicates recursive to be used on directories

hehe3301
  • 746
  • 7
  • 17
-2

Drive letter can be used in the source like

scp /c/path/to/file.txt user@server:/dir1/file.txt
Igor Mukhin
  • 15,014
  • 18
  • 52
  • 61