104

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.

2
  • 2
    The standard path on windows/dos says to use \ backslash, so try C:\desktop\myfolder\deployments\ Jan 23, 2012 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, 2019 at 20:16

7 Answers 7

94

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.

3
  • scp -r [email protected]:/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 [email protected]:/var/www/vhosts/mywork D:\test ---gives error "ssh: Could not resolve hostname D: Name or service not known lost connection"
    – pTi
    Mar 26, 2016 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. Jun 8, 2016 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 <port> -r ./localdir user@host:"D:\remotedir"
    – serigado
    Jun 11, 2020 at 16:16
36

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.

5
  • 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 2, 2015 at 8:10
  • 1
    this does not work to get the files May 18, 2017 at 6:02
  • 7
    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 6, 2019 at 7: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, 2019 at 16:47
  • 1
    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 9 at 0:12
22

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

3
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

1

You can also try this:

scp -r /cygdrive/c/desktop/myfolder/deployments/ user@host:/path/to/whereyouwant/thefile
1
  • 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, 2015 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

2
  • 1
    downloaded that mobaXTerm and turned out it had a virus. Messed up some stuff for me good
    – Damien
    Oct 6, 2016 at 13:55
  • @Damien then you did not download it from the site I provided
    – hehe3301
    Feb 22, 2017 at 18:24
-2

Drive letter can be used in the source like

scp /c/path/to/file.txt user@server:/dir1/file.txt
2
  • 2
    cp: cannot stat ‘/c/Users/xxx/Documents/rocket.chat/priv-key.ppk’: No such file or directory
    – The Onin
    Jul 14, 2016 at 13:26
  • 1
    '/drives/c/Users/xxx/Documents/rocket.chat/priv-key.pp" will work Nov 19, 2016 at 1:47

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