sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
4.02k stars 934 forks source link

TimeOut in Connect on iOS #1476

Open TomQv opened 3 months ago

TomQv commented 3 months ago

I'm only receiving Timeout-Exception trying to connect to my ftp-server with iOS:

var client = new SftpClient("files.qvgps.com", “user”, “password");
client.Connect();
Renci.SshNet.Common.SshOperationTimeoutException: Connection failed to establish within 30000 milliseconds.
  at Renci.SshNet.Abstractions.SocketAbstraction.ConnectCore (System.Net.Sockets.Socket socket, System.Net.EndPoint remoteEndpoint, System.TimeSpan connectTimeout, System.Boolean ownsSocket) [0x000a4] in <f1d5e967bcbc48fcb33dd5c4b79edfbe>:0
  at Renci.SshNet.Abstractions.SocketAbstraction.Connect (System.Net.Sockets.Socket socket, System.Net.EndPoint remoteEndpoint, System.TimeSpan connectTimeout) [0x00000] in <f1d5e967bcbc48fcb33dd5c4b79edfbe>:0
  at Renci.SshNet.Connection.ConnectorBase.SocketConnect (System.Net.EndPoint endPoint, System.TimeSpan timeout) [0x0000e] in <f1d5e967bcbc48fcb33dd5c4b79edfbe>:0

With UWP, it works fine.

SSH.NET 2024.1.0 Visual Studio Community 2022 for Mac Version 17.6.12 (build 410) Xamarin.iOS Version: 16.4.0.23 Visual Studio Community

Are there maybe any additional steps required on iOS to use sftp?

TomQv commented 3 months ago

Ok, did some more tests, seems like is was my router. I disconnected from Wifi and used mobile data, then it worked. Then I restarted my router and then it also worked with Wifi. No timeouts anymore. Strange, but it looks like, as it was no SSH.NET problem.

Rob-Hague commented 3 months ago

Yeah so despite the stack trace the real problem is waiting too long in Socket.Connect:

https://github.com/sshnet/SSH.NET/blob/3dda5c92ceb373a0947ee02e105516309e15c8cb/src/Renci.SshNet/Abstractions/SocketAbstraction.cs#L88-L90

I imagine (or hope) you would observe a similar hang without the library:

using System.Net.Sockets;

using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);

socket.Connect("files.qvgps.com", 22);