SSH.NET
SSH.NET copied to clipboard
Can't use as socks tunnel on MAUI application (.net 8)
When I trying to use var _port= new ForwardedPortDynamic("127.0.0.1", 5000), On that's code:
_client = new SshClient(s);
_client.HostKeyReceived += (sender, e) =>
{
e.CanTrust = true;
};
_client.Connect();
_client.AddForwardedPort(_port);
_client.ErrorOccurred += _client_ErrorOccurred;
_port.Start();
I have received exception like "Session operation has timed out". But when I have used _client.createCommand it's works fine and returns good output. What's i doing wrong ?
That looks about right to me. There are a couple of examples in the tests:
https://github.com/sshnet/SSH.NET/blob/16d84d0395a277a89a7487ff1b731d016d430dc2/test/Renci.SshNet.IntegrationTests/SshTests.cs#L472
What is the stack trace of the exception?
That looks about right to me. There are a couple of examples in the tests:
SSH.NET/test/Renci.SshNet.IntegrationTests/SshTests.cs
Line 472 in 16d84d0 public void Ssh_DynamicPortForwarding_IPv4()
What is the stack trace of the exception?
Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout) Renci.SshNet.Session.Renci.SshNet.ISession.WaitOnHandle(WaitHandle waitHandle) Renci.SshNet.Channels.Channel.WaitOnHandle(WaitHandle waitHandle) Renci.SshNet.Channels.ChannelDirectTcpip.Open(String remoteHost, UInt32 port, IForwardedPort forwardedPort, Socket socket) Renci.SshNet.ForwardedPortDynamic.HandleSocks4(Socket socket, IChannelDirectTcpip channel, TimeSpan timeout) Renci.SshNet.ForwardedPortDynamic.HandleSocks(IChannelDirectTcpip channel, Socket clientSocket, TimeSpan timeout) Renci.SshNet.ForwardedPortDynamic.ProcessAccept(Socket clientSocket)
I have tried to use putty with dynamicport setting for that connection. All works fine. Any ideas ? :(
No bright ideas, sorry. It looks like it negotiates the socks request but it is timing out waiting for a response from the server after requesting the port forwarding.
There are a few events on the port class that you could subscribe to and check: _port.RequestReceived, _port.Exception, _port.Closing
Depending on how much control you have over the client and server, you could try socks5 with the client, or see if the server logs have anything useful
You could also try a pre-release package which has some logging. See https://github.com/sshnet/SSH.NET#using-pre-release-nuget-package and https://github.com/sshnet/SSH.NET/blob/develop/docfx/logging.md
At the Trace level it will be quite verbose but will show all the SSH packets being sent/received