This project is read-only.

SOCKS5: Host unreachable.

Sep 10, 2015 at 4:26 PM
I am trying to connect to an external SFTP server via a SOCKS proxy server using SSH.NET library (V2013.4.7) but I'm getting error "SOCKS5:Host unreacheable". The connection works fine in other tools such as WinSCP.

I am using class SftpClient instantiated with a PasswordConnectionInfo using ProxyType.Socks5 protocol as shown by the given constructor below: public PasswordConnectionInfo(string host,int port,string username,string password,ProxyTypes proxyType,string proxyHost,int proxyPort) - the Host port number is 30206 and the proxy port here is the default 1080

Debugging ssh.net source code, The error is being thrown after my machine sends the connection request to the Proxy and awaits a response in class Session.cs:
// Send port
 this.SocketWriteByte((byte)(this.ConnectionInfo.Port / 0xFF));
 this.SocketWriteByte((byte)(this.ConnectionInfo.Port % 0xFF));
// Read Server SOCKS5 version
 if (this.SocketReadByte() != 5) **** error is thrown here after about 2 minutes!
Using WireShark, I checked that my machine/Proxy handshake was successful, and the IP address of the external server is being looked up correctly - The bit I am not sure about here in the library source code (above) is the 2 lines where the port number is being specified. What is the use of "0xFF"?

According to Socks5 protocol, the port number is specified at: [field 6: network byte order port number, 2 bytes]. I am having a suspucion about the Port number not being sent correctly!

Grateful if anyone can throw some ligth upon this or if someone had similar issues or if anyone had this working successfully.

Thank you.