133

I am running a putty client on a Windows machine to connect successfully to a Linux box. Now I want to be able to copy a file from the Linux machine under the path /home/ubuntu/myfile to C:/Users/Anshul/Desktop on my local computer. The user at the Windows machine is anshul. I am giving the following command on putty but it is not working:

scp /home/ubuntu/myfile ip_address_of_windows_machine:C:/Users/Anshul/Desktop 

I think the path for the Windows machine is wrong. Please help as I have banged my head on a large number of forums but none seem to give correct path for Windows server. Don't suggest alternate options like WinScp

5
  • 4
    So what are you running for an ssh service on Windows? The correct answer would depend on your answer to this question. Apr 19, 2012 at 19:58
  • 6
    The phrase "Not working" is the absolute least useful thing you can say when asking for help. WHAT isn't working? What results do you actually get? Are there any error message? If so, include them in your post. Sep 24, 2012 at 0:29
  • Try 'ssh -v ip_address_of_windows_machine dir' If you can't ssh to the box, then you can't scp to it either. The '-v' option will give some feedback about how it is trying to connect and help figure out whether it is the ip address, the sshd server on the windows box, etc...
    – Dave X
    Apr 28, 2015 at 9:41
  • 2
    scp hello.txt Administrator@WINDOWS_MACHINE_IP:hello.txt This copied the file to C:\Users\Administrator\hello.txt. Sep 22, 2017 at 21:26
  • @emoblazz has the best answer if you don't want to install third party things. you basically make sure you have your username and @ before Jul 21, 2019 at 16:26

16 Answers 16

141

This one worked for me.

scp /home/ubuntu/myfile username@IP_of_windows_machine:/C:/Users/Anshul/Desktop 
6
  • 40
    This is the only true answer to this question. Dec 5, 2018 at 19:07
  • 6
    In my case, the command worked but not completely. The following message is shown: ssh: connect to host <ip_address> port 22: Connection refused. Aug 29, 2019 at 16:45
  • 1
    @AlexJavarotti The error you got might be caused by the firewall setting.
    – willisc
    Sep 25, 2019 at 14:09
  • So I realize that the question was not about MacOS, but on a Mac, I found both the form suggested in this answer worked, but also a variant that dropped the initial '/'. So something like ...:C:/Users/...etc. Not terribly different, but worth noting I suppose.
    – cycollins
    Jul 19, 2020 at 6:29
  • @ChouW "Connection refused" is not a firewall issue. It's simply that the service is not started, and thus is not bound to the port 22.
    – Déjà vu
    Aug 19, 2021 at 6:46
93

Download pscp from Putty download page, then use it from Windows Command Line CMD as follows:

pscp username_linux_machine@ip_of_linux_machine:/home/ubuntu/myfile.ext C:\Users\Name\Downloads

Copying starts once you enter the password for the Linux machine.

4
  • This command didn't work for me until I added the -scp flag.
    – Steven
    Oct 19, 2020 at 2:56
  • scp that ships with Windows 10 had problems finalizing larger transfers (weird error "<filename>: Is a directory", leaving a partial file although download was complete). pscp seems to do be working just fine! Sep 28, 2021 at 23:07
  • 4
    I love it when something works the first time. Thanks. Mar 3, 2022 at 13:17
  • Pay attention if you use an ssh key generated by ssh-keygen you need to convert that to the Putty-specific format using PuTTYgen.
    – MegaCasper
    Aug 25 at 11:15
69

Try this, it really works.

$ scp username@from_host_ip:/home/ubuntu/myfile /cygdrive/c/Users/Anshul/Desktop

And for copying all files

$ scp -r username@from_host_ip:/home/ubuntu/ *. * /cygdrive/c/Users/Anshul/Desktop
8
  • 7
    Notice the "/cygdrive/c" in the path? This will work after installing CYGWIN. Still is a great suggestion! Jan 17, 2017 at 19:23
  • 2
    On Windows you may also opt to use pscp (part of the PuTTY package, or can be downloaded separately) putty.org
    – The-Duck
    Jun 8, 2017 at 6:07
  • @SalvadorValencia ubuntu@ip-172-31-22-20:~$ scp try.sh Administrator@XXXX:/cygdrive/c/Users/Administrator/Desktop ssh: connect to host XXXX port 22: Connection refused lost connection Aug 31, 2017 at 10:15
  • 1
    I am on Linux server and want to copy to windows server ! Also will cygwin listen on port 22 ? or else which port should we opened as my windows server is in aws ec2 instance Aug 31, 2017 at 10:16
  • 2
    @AshishKarpe this looks like the command ran but it encountered router/firewall issues. Do a "telnet XXXX 22" and see if it opened the port. If not then stackoverflow should help you solve it with iptables or the windows firewall, for example. Nov 28, 2017 at 18:33
51

Access from Windows by Git Bash console (also works for CMD and PowerShell):

scp user@ip:/dir1/dir2/file "D:\dir1\dir2"
5
  • 7
    Finally some advice that works, thanks!
    – MSC
    Mar 27, 2019 at 20:43
  • Nice! This worked well and is very simple.
    – Zack A
    Jan 6, 2022 at 15:41
  • path to be not given in inverted commas, apart from that answer is correct. Thanks. Feb 10, 2022 at 19:50
  • in order to use a domain account to authenticate to the Windows Server the syntax is: scp file.ext ad_user@domain.subdomain.com@windows_IP:file.ext ( yes 2 @ symbols !! ) Mar 30, 2022 at 1:08
  • You might get a permission error if you're trying to paste something in C drive, so you might want to paste file in some other directory. Apr 26, 2022 at 17:23
15

You could use something like the following

scp -r linux_username@linux_address:path/to/file path/to/local/directory

This will copy file to the specified local directory on the system you are currently working on.

The -r flag tells scp to recursively copy if the remote file is a directory.

9

Windows doesn't support SSH/SCP/SFTP natively. Are you running an SSH server application on that Windows server? If so, one of the configuration options is probably where the root is, and you would specify paths relative to that root. In any case, check the documentation for the SSH server application you are running in Windows.

Alternatively, use smbclient to push the file to a Windows share.

5
  • 21
    »Windows doesn't support SSH/SCP/SFTP natively.« Neither does Linux or any other OS. It always needs a service for that.
    – Joey
    Apr 19, 2012 at 20:40
  • @Joey - Number of times I've seen a Linux distro intended to connect to the internet but not have SSH/SCP/SFTP preinstalled... never? If you don't think Linux or macOS support those things natively, then you're either clueless or the debate is over what the word "natively" means. Jul 18, 2017 at 18:02
  • 2
    @ArtOfWarfare I'm pretty sure Ubuntu doesn't have SSH server installed by default. SSH client yes, but not server. Sep 13, 2017 at 12:35
  • @BrunoFinger - I just installed Lubuntu a few days ago, and I can confirm it didn't have an SSH server by default. But Lubuntu is a very bare bones install of Ubuntu - I intentionally chose it because of how minimal its install footprint was. I think most of the other pre-built configurations have it already installed, and in any event, getting the ssh server installed was a single line command (off the top of my head, I think it was sudo apt-get install sshd.) Seconds later I was able to SSH in from another computer. Sep 13, 2017 at 12:50
  • 2
    @Joey Nonetheless, the answer is useful, because Windows ships the sshd service as an optional install even in the Professional SKU. (I wonder if Enterprise enables it by default). It would be easy to overlook, since so many other platforms enable this service by default, so it bears mentioning. One has to go to "Settings/Apps/Optional features" and install "OpenSSH Server". Also the service has to be started, and should be set to automatic launch.
    – cycollins
    Jul 19, 2020 at 6:43
4

For all, who has installed GiT completly with "Git Bash": You can just write:

scp login@ip_addres:/location/to/folders/file.tar .

(with space and DOT at the end to copy to current location). Than just add certificate (y), write password and that's all.

1
  • 1
    That's simple and great solution for people trapped in Win env, especially that git bash is easily available in portable mode, for those working without admin rights. Thanks!
    – kurp
    Nov 13, 2019 at 12:07
4

Your code isn't working because c:/ or d:/ is totally wrong for linux just use /mnt/c or/mnt/c

From your local windows10-ubuntu bash use this command:

for download: (from your remote server folder to d:/ubuntu) :

scp username@ipaddress:/folder/file.txt /mnt/d/ubuntu

Then type your remote server password if there is need.

for upload: (from d:/ubuntu to remote server ) :

scp /mnt/d/ubuntu/file.txt username@ipaddress:/folder/file.txt 

Then type your remote server password if there is need. note: I tested and it worked.

4

I had to use pscp like above Hesham's post once I downloaded and installed putty. I did it to Windows from Linux on Windows so I entered the following:

c:\ssl>pscp username@linuxserver:keenan/ssl/* .

This will copy everything in the keenan/ssl folder to the local folder (.) you performed this command from (c:\ssl). The keenan/ssl will specify the home folder of the username user, for example the full path would be /home/username/keenan/ssl. You can specify a different folder using a forward slash (/), such as

c:\ssl>pscp username@linuxserver:/home/username/keenan/ssl/* .

So you can specify any folder at the root of Linux using :/.

2

To send a file from windows to linux system

scp path-to-file user@ipaddress:/path-to-destination

Example:

scp C:/Users/adarsh/Desktop/Document.txt root@127.0.0.1:/tmp

keep in mind that there need to use forward slash(/) inplace of backward slash(\) in for the file in windows path else it will show an error

C:UsersadarshDesktopDocument.txt: No such file or directory

. After executing scp command you will ask for password of root user in linux machine. There you GO...

To send a file from linux to windows system

scp -r user@ipaddress:/path-to-file path-to-destination

Example:

scp -r root@127.0.0.1:/tmp/Document.txt C:/Users/adarsh/Desktop/

and provide your linux password. only one you have to add in this command is -r. Thanks.

2

As @Hesham Eraqi suggested, it worked for me in this way (transfering from Ubuntu to Windows (I tried to add a comment in that answer but because of reputation, I couldn't)):

pscp -v -r -P 53670 user@xxx.xxx.xxx.xxx:/data/genetic_map/sample/P2_283/* \\Desktop-mojbd3n\d\cc_01-1940_data\

where:

-v: show verbose messages.
-r: copy directories recursively.
-P: connect to specified port.
53670: the port number to connect the Ubuntu server.
\\Desktop-mojbd3n\d\genetic_map_data\: I needed to transfer to an external HDD, thus I had to give permissions of sharing to this device.

1

Here is the solution to copy files from Linux to Windows using SCP without password by ssh:

  1. Install sshpass in Linux machine to skip password prompt

  2. Script

    sshpass -p 'xxxxxxx' scp /home/user1/*.* testuser@x.x.x.x:/d/test/

Details:

sshpass -p 'password' scp /source_path/*.* windowsusername@windowsMachine_ip:/destination_drive/subfolder/
0

Open bash window. Preferably git bash. write

scp username@remote_ip:/directory_of_file/filename 'windows_location_you_want_to_store_the_file'

Example:

Suppose your username is jewel

your IP is 176.35.96.32

your remote file location is /usr/local/forme

your filename is logs.zip

and you want to store in your windows PC's D drive forme folder then the command will be

scp jewel@176.35.96.32:/usr/local/forme/logs.zip 'D:/forme'

**Keep the local file directory inside single quote.

-2

I know this is old but I was struggling with the same. I haven't found a way to change directories, but if you just want to work with the C drive, scp defaults to C. To scp from Ubuntu to Windows, I ended up having to use (notice the double back-slashes):

scp /local/file/path user@111.11.11.111:Users\\Anshul\\Desktop

Hope this helps someone.

2
  • Will it work for Administrator user ? What configurations do we need to do in Windows box ? Aug 31, 2017 at 9:52
  • ubuntu@ip-172-31-22-20:~$ scp try.sh Administrator@xxxxxxx:Users\\Administrator\\Desktop ssh: connect to host "xxxxxx" port 22: Connection refused lost connection Aug 31, 2017 at 9:55
-10

Try this:

scp /home/ubuntu/myfile C:\users\Anshul\Desktop
1
  • Yes it worked fine. Since I am running this on my local Windows PC and I am running SCP it knows about my C:\ drive. I am not running this command from the Linux box, I am running it from my Windows PC. Feb 21, 2013 at 18:46
-13

If you want to copy paste files from Unix to Windows and Windows to Unix just use filezilla with port 22.

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