FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

Problem connecting to FTPS servers

Open Stonesmith92 opened this issue 4 years ago • 3 comments

Computer OS: ? Window 10 FluentFTP Version: ? 35.0.5.0 <write details about your bug report / feature request here> I am trying to connect to an FTPS server using .Net Framework 4.7. On the first try if will connenct without any problem, but on the seconf try i will get the following exception message: "Timed out trying to read data from the socket stream!"

Using the follong code:

FtpClient client = new FtpClient(Host, Port, new NetworkCredential(UserName, Password));

try
{
	client.EncryptionMode = FtpEncryptionMode.Auto;
	client.ConnectTimeout = int.MaxValue;

	client.ValidateAnyCertificate = true;
	client.DataConnectionType = FtpDataConnectionType.PASV;
	client.DownloadDataType = FtpDataType.Binary;
	client.RetryAttempts = 5;
	client.SocketPollInterval = 1000;
	client.ConnectTimeout = 2000;
	client.ReadTimeout = 2000;
	client.DataConnectionConnectTimeout = 2000;
	client.DataConnectionReadTimeout = 2000;
	client.Encoding = System.Text.UTF8Encoding.UTF8;
        client.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls | SslProtocols.Ssl2 | SslProtocols.Ssl3;
	client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);

	client.Connect();
	client.Disconnect();
	client.Dispose();
}
catch(Exception e){}

private void OnValidateCertificate(FtpClient c, FtpSslValidationEventArgs e) {
			var cert2 = new X509Certificate2(e.Certificate);
			e.Accept = cert2.Verify();
		}

Logs : And here are the logs:

On the first attempt:

# Connect()
Status:   Connecting to 192.168.10.168:2112
Response: 220 test wellcome message
Command:  AUTH TLS
Response: 234 Auth command OK 
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0.8039081.
Command:  USER testuser
Response: 331 Password required for testuser
Command:  PASS ******
Response: 230 Login OK
Command:  PBSZ 0
Response: 200 PBSZ=0
Command:  PROT P
Response: 200 PROT command OK
Command:  FEAT
Response: 211-Features supported
Response: REST STREAM
Response: EPRT
Response: EPSV
Response: SIZE
Response: MDTM
Response: MFMT
Response: AUTH
Response: PBSZ
Response: PROT
Response: CCC
Response: MLST type*;size*;modify*;
Response: MLSD
Response: UTF8
Response: MODE Z
Response: 211 End
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 OK, UTF8 ON.
Command:  SYST
Response: 215 UNIX Type: L8
Command:  QUIT
Response: 221 Good-Bye
Status:   Disposing FtpSocketStream...

# Dispose()
Status:   Disposing FtpClient object...
Status:   Disposing FtpSocketStream...

On the second attempt:

# Connect()
Status:   Connecting to 192.168.10.168:2112
Response: 220 test wellcome message
Command:  AUTH TLS
Response: 234 Auth command OK 
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0.4010896.
Command:  USER testuser
Status:   Disposing FtpSocketStream...

Stonesmith92 avatar Oct 06 '21 06:10 Stonesmith92

I'm creating FluentFtp client to get files from FileZilla FTPS server and never seen that second instance fails to connect. Actually I create a lot of FluentFtp clients that causes the socket TIME_WAIT issue sometimes.

I suppose you should check your source code or provide the minimal reproducable test case that can be executed.

It would be better to use using (FtpClient client = new FtpClient(...)) and do not hide an exception with empty catch

oleksabor avatar Oct 23 '21 13:10 oleksabor

Do you also have this problem with v33.0.3 I'm seeing a socket exception with releases after 33.0.3, with FTPS and Implicit mode Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

DavidDeSloovere avatar Oct 25 '21 14:10 DavidDeSloovere

I think you are setting too many things up. Just try using client.AutoConnect() with the latest FluentFTP.

robinrodricks avatar Nov 16 '21 19:11 robinrodricks

@oleksabor Is this still an issue for you? @DavidDeSloovere Please open a separate issue if this is still of concern for you.

Otherwise, I suggest we close this in a week or so.

FanDjango avatar Oct 27 '22 19:10 FanDjango