简体   繁体   中英

Renci ssh.net No connection could be made because the target machine actively refused it

We recently deployed a project into production and are now receiving this error message when we attempt to connect to the external sftp machine, "No connection could be made because the target machine actively refused it". When I was developing the application and testing it, we had no issues connecting to this server.

What would be different? I have administrative privileges and the app pool on the production server does not. I'm not sure if this could be what's causing the issue or if it may be something on the external client's server or their firewall blocking us.

If you are using localhost , specify 127.0.0.1 instead.

When I was using SSH.Net and the host was specified as localhost it threw the exception that the host actively refused the connection WSAECONNREFUSED - 10061 . When I specified 127.0.0.1 instead, the connection could be made. I think this is due to the implementation in SSH.Net:

    internal static IPAddress GetIPAddress(this string host)
    {
        IPAddress ipAddress;
        if (!IPAddress.TryParse(host, out ipAddress))
            ipAddress = Dns.GetHostAddresses(host).First();

        return ipAddress;
    }

Which does not resolve a valid hostname for localhost , apparently. C# Interactive yields the following:

> Console.WriteLine(Dns.GetHostAddresses("localhost").First());
::1

The value ::1 does not seem to be a valid IP address for sockets to use.

This is a standard TCP error

WSAECONNREFUSED - 10061

From the Client's point of view it means 'there is no socket at that address listening to that port' (the "actively refused" is a red herring).

i) check the address ii) check the port iii) check firewall(s)

From our extensive experience (we offer own networking components) -- it's a firewall problem. The firewall doesn't let your requests pass. It's a common situation when you run say Putty, and it works, but your code doesn't. This is because many firewalls detect well-known applications and let them pass, while preventing other applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM