Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
1.1k views
in .NET FTP by (780 points)
Let's say my server can support either FTP or SCP, but I don't know which. If it's using SCP and my SecureFTPConnection client is set to the FTP protocol, I will quickly get a SocketException (10061 Connection Refused). This is nice because I can catch the exception, check for the 10061 code, and switch to using SCP instead because I know FTP isn't supported.

Now consider the other direction. The server is using FTP, but my client is set to the SCP protocol. In this case I get an IOException with the message "Failed to connect to 192.168.43.45:22 within timeout 10000 ms" and this exception is actually raised pretty quickly instead of after the full timeout. Not so nice because an IOException can be raised for a multitude of other reasons (actual timeouts because the server is not present, other timeouts like DNS issues, etc). So it's harder to know with the IOException what the true reason is. Did it really time out? Was the protocol unsupported?

So what's the difference? Why do I get an IOException instead of a SocketException which would be more helpful? Is there an easier way to know that the protocol being used isn't supported? My current plan if I get an IOException is to try a basic TCP connection afterwards with a short timeout using a raw socket and catching the 10061 SocketException myself so I know whether the connection is being actively refused. And in this case I'll actually ask the user if they want to use an unsecure connection instead. But it would sure be nice if I knew this from the SecureFTPConnection client itself.

FYI, I think I also get the same scenarios when choosing between SFTP and FTP, but I haven't been able to fully test this.

3 Answers

0 votes
by (162k points)
Maybe post a snippet of debug level logging from the SCP protocol attempt to port 22 - it might tell us something.
0 votes
by (780 points)
Here you go. In this case my server only supported FTP but I was trying to connect using the SCP protocol. The connection attempt fails after about a second (which is good since it's not waiting the entire 10 seconds for my timeout) and I receive the failure as an IOException instead of a SocketException.

INFO [FTPConnection] 13 May 2015 11:13:43.048 : OS: 6.2.9200.0, CLR: 4.0.30319.34209, DLL: 8.6.6.20
INFO [FTPConnection] 13 May 2015 11:13:43.049 : Built: 15-Apr-2015 20:01:37 BST
DEBUG [LicenseProperties] 13 May 2015 11:13:43.050 : Looking for subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO (fallback )
DEBUG [LicenseProperties] 13 May 2015 11:13:43.050 : Found license subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO
DEBUG [LicenseProperties] 13 May 2015 11:13:43.051 : Looking for subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO (fallback )
DEBUG [LicenseProperties] 13 May 2015 11:13:43.051 : Found license subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO
DEBUG [LicenseProperties] 13 May 2015 11:13:43.054 : Looking for subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO (fallback )
DEBUG [LicenseProperties] 13 May 2015 11:13:43.054 : Found license subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO
DEBUG [LicenseProperties] 13 May 2015 11:13:43.054 : Looking for subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO (fallback )
DEBUG [LicenseProperties] 13 May 2015 11:13:43.054 : Found license subkey Software\Enterprise Distributed Technologies\edtFTPnet PRO
DEBUG [SFTPMessageStore] 13 May 2015 11:13:43.061 : Set timeout=10000
INFO [LicenseProperties] 13 May 2015 11:13:43.066 : Licence expiry date: 12/31/9999
INFO [LicenseProperties] 13 May 2015 11:13:43.066 : Production license
INFO [LicenseProperties] 13 May 2015 11:13:43.067 : Licence expiry date: 12/31/9999
INFO [LicenseProperties] 13 May 2015 11:13:43.067 : Production license
DEBUG [SSHSCPClient] 13 May 2015 11:13:43.068 : Setting up fallback kbi prompt based on supplied password
DEBUG [HostNameResolver] 13 May 2015 11:13:43.071 : Resolving 192.168.43.40
DEBUG [HostNameResolver] 13 May 2015 11:13:43.072 : 192.168.43.40 resolved to 192.168.43.40
DEBUG [SSHSCPClient] 13 May 2015 11:13:43.072 : Connecting directly to SFTP server 192.168.43.40:22
INFO [BaseSocket] 13 May 2015 11:13:43.072 : Connecting to 192.168.43.40:22 with timeout 10000 ms
ERROR [BaseSocket] 13 May 2015 11:13:44.096 : Failed to connect to 192.168.43.40:22 within timeout 10000 ms
DEBUG [FTPConnection] 13 May 2015 11:13:44.111 : Closing connection [instance=0,abrupt=False]
WARN [FTPConnection] 13 May 2015 11:13:44.126 : Caught exception closing connection: The SFTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
DEBUG [SFTPMessageStore] 13 May 2015 11:13:44.126 : Set timeout=5000
DEBUG [FTPConnection] 13 May 2015 11:13:44.127 : Closing connection [instance=0,abrupt=False]
WARN [FTPConnection] 13 May 2015 11:13:44.130 : Caught exception closing connection: The SFTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
0 votes
by (162k points)
It's not obvious what's happening. We will try to replicate it.

Categories

...