0

I am trying to copy one file from Linux (CentOS) to Windows.

scp file.txt [email protected]:C:/

The output I get is:

ssh: connect to host x.x.x.x port 22: Connection refused
lost connection

x.x.x.x is the IP of my Windows machine. Port 22 is open but I cannot connect via telnet from CentOS to Windows

curl -v x.x.x.x:22

* About to connect() to 10.109.10.135 port 22 (#0)
*   Trying 10.109.10.135... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host

The firewall is disabled on Windows and Port 22 is open. I can connect via putty client to CentOS on that port. I'm quite confused here.

Thanks.

5
  • 6
    obviously the first question I should ask is: is there a sshd running on the windows machine? which windows version?
    – hyph
    Mar 28, 2017 at 20:27
  • I am using Windows 2012, but I would like this to work on Win10 as well. If there is a way, else I will fall back to winscp. Mar 28, 2017 at 20:36
  • What are you using for SSH on the windows side? Sometimes Windows-based ssh will disable SCP. You may have to check the GUI on the windows side. Although it's weird you would get "connection refused" which would indicate a TCP failure which should be affecting scp and ssh equally.
    – Bratchley
    Mar 28, 2017 at 20:37
  • Can you putty SSH to the Windows machine on port 22? Usually when the error code is "Connection refused" no program is listening on port 22. Try netstat -a on the Windows machine to see if port 22 is listening. Mar 28, 2017 at 20:39
  • Part of the confusion sounds like you're not familiar with networks and protocols. curl isn't telnet. Just because you're using curl (a program that talks HTTP to web servers) to port 22 doesn't make it suddenly start using a different protocol. Also, telnet is to port 23, so even if you did have telnet it would still be wrong because you really need something that uses the ssh protocol. Mar 28, 2017 at 23:17

5 Answers 5

5

The fact that you can initiate a connection from the windows box to the Linux box does in no way imply that the reverse is possible as well.

If you want to be able to scp to your Windows machine, you need to make sure you have a SSH service running on your Windows machine which allows for incoming ssh connections. The fact that you get a 'connection refused' message suggests that that isn't set up or the service is not started.

Since you share that you've been able to reach your Linux machine using ssh, it's probably easier to just turn things around, and run scp on the Windows machine instead.

1
  • Setting up SSH on older Windows server versions is not a trivial process from my personal experience, so your suggestion would be ideal if possible for the OP. Mar 29, 2017 at 19:50
0

I've would simply implement ftp or sftp server on the Windows side (installation will open port for u) and do it this way. It will get job done much easier. With no NTFS issues etc.

0

Download pscp in windows and use

pscp -P 801 [email protected]:/root/filename.txt ./

-P is the option to supply a port number.

1
  • The OP was trying to copy from Linux to Windows, not the other way round. Jan 4, 2020 at 17:58
0

You could as well mount the windows computer's drive as smb share via cifs on your linux machine and perform a local copy.

0

I have resolved my issue using the "-P" parameter.

Usually, SCP is using port 22 as a default port, but for security reasons, you may change the port to another port. For example, here port 2249 is used.

$ scp -P 2249 Label.pdf [email protected]:.

[email protected]'s password:
Label.pdf 100% 3672KB 262.3KB/s 00:14

For other parameters please refer

https://www.tecmint.com/scp-commands-examples/

1
  • 1
    Why and how do you believe that this answers the question?   Are you assuming that the OP has scp running on port 2249 now?  (Why?)   Are you suggesting that they should reconfigure their server to use port 2249?  (How?) Feb 29 at 18:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .