131

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

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
user1344963
  • 1,319
  • 2
  • 9
  • 4
  • 4
    So what are you running for an ssh *service* on Windows? The correct answer would depend on your answer to this question. – Ernest Friedman-Hill Apr 19 '12 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. – Jeremy J Starcher Sep 24 '12 at 00: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 '15 at 09:41
  • 2
    `scp hello.txt Administrator@WINDOWS_MACHINE_IP:hello.txt` This copied the file to `C:\Users\Administrator\hello.txt`. – leodotcloud Sep 22 '17 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 – ThinkBonobo Jul 21 '19 at 16:26

16 Answers16

141

This one worked for me.

scp /home/ubuntu/myfile username@IP_of_windows_machine:/C:/Users/Anshul/Desktop 
emoblazz
  • 1,411
  • 1
  • 7
  • 3
  • 40
    This is the only true answer to this question. – Mithridates the Great Dec 05 '18 at 19:07
  • 6
    In my case, the command worked but not completely. The following message is shown: ssh: connect to host port 22: Connection refused. – Alex Javarotti Aug 29 '19 at 16:45
  • 1
    @AlexJavarotti The error you got might be caused by the firewall setting. – willisc Sep 25 '19 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 '20 at 06: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 '21 at 06:46
  • @Breakingnotsobad can't remember since it was 2 years ago. I thought maybe the firewall in the windows os block the request and we'll get the "connection refused" error – willisc Aug 19 '21 at 18:04
94

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.

ifnotak
  • 4,147
  • 3
  • 22
  • 36
Hesham Eraqi
  • 2,444
  • 4
  • 23
  • 45
  • This command didn't work for me until I added the -scp flag. – Steven Oct 19 '20 at 02:56
  • `scp` that ships with Windows 10 had problems finalizing larger transfers (weird error ": Is a directory", leaving a partial file although download was complete). `pscp` seems to do be working just fine! – Bigue Nique Sep 28 '21 at 23:07
  • 4
    I love it when something works the first time. Thanks. – Mark Longmire Mar 03 '22 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 '23 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
fluffyBatman
  • 6,524
  • 3
  • 24
  • 25
  • 7
    Notice the "/cygdrive/c" in the path? This will work after installing CYGWIN. Still is a great suggestion! – Salvador Valencia Jan 17 '17 at 19:23
  • 2
    On Windows you may also opt to use pscp (part of the PuTTY package, or can be downloaded separately) http://www.putty.org/ – The-Duck Jun 08 '17 at 06: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 – Ashish Karpe Aug 31 '17 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 – Ashish Karpe Aug 31 '17 at 10:16
  • How to copy a large file using this? – user3806649 Nov 03 '17 at 12:01
  • 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. – Salvador Valencia Nov 28 '17 at 18:33
  • I am facing a similar problem, but instead of cygwin I am using freeSSHd. When I scp my file from linux to the windows server, my linux machine says scp is successful, but I cannot see the file in the folder I mentioned. Any help on this? – nidHi Feb 13 '18 at 04:41
  • Default in April 2018 Update for Win10 - https://www.bleepingcomputer.com/news/microsoft/windows-10-openssh-client-installed-by-default-in-april-2018-update/ Regarding the destination, you can also just use "."to drop the file in your current working directory: scp username@from_host_ip:/home/ubuntu/myfile . – Paul Masek Dec 07 '18 at 16:11
50

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

scp user@ip:/dir1/dir2/file "D:\dir1\dir2"
Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
byteprom
  • 541
  • 4
  • 4
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.

Atif
  • 345
  • 1
  • 4
  • 16
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.

George
  • 6,886
  • 3
  • 44
  • 56
theglauber
  • 28,367
  • 7
  • 29
  • 47
  • 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 '12 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. – ArtOfWarfare Jul 18 '17 at 18:02
  • 2
    @ArtOfWarfare I'm pretty sure Ubuntu doesn't have SSH server installed by default. SSH client yes, but not server. – Bruno Finger Sep 13 '17 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. – ArtOfWarfare Sep 13 '17 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 '20 at 06: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
    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 '19 at 12:07
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 :/.

halfer
  • 19,824
  • 17
  • 99
  • 186
Keenan Stewart
  • 594
  • 6
  • 9
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.

Baris Vvolf
  • 141
  • 2
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.

ADARSH K
  • 606
  • 1
  • 8
  • 21
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.

giannkas
  • 178
  • 3
  • 14
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/
serenesat
  • 4,611
  • 10
  • 37
  • 53
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.

Zenith
  • 1,037
  • 1
  • 10
  • 21
-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.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Acmag
  • 1
  • 2
  • Will it work for Administrator user ? What configurations do we need to do in Windows box ? – Ashish Karpe Aug 31 '17 at 09: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 – Ashish Karpe Aug 31 '17 at 09:55
-10

Try this:

scp /home/ubuntu/myfile C:\users\Anshul\Desktop
Pang
  • 9,564
  • 146
  • 81
  • 122
Corey Burnett
  • 7,312
  • 10
  • 56
  • 93
  • 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. – Corey Burnett Feb 21 '13 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.