Description
When connecting to a FileZilla FTPS server with FluentFTP, we get a System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
when trying to list files.
We can establish the initial connection, we can log in, but when FluentFTP tries to establish the data connection via EPSV, it errors out with that exception.
Our research so far seems to point towards the TLS resumption failing. FTPS servers insist on the data connection resuming the TLS session from the control connection, and that seems to be failing. Curiously, this only occurs on dotnetcore on Linux or WSL. Everything works fine on dotnetcore on Windows.
Versions: DotNetCore 2.1.5 FluentFTP 19.2.2
OS Ubuntu 18.04 / Windows 10 WSL Ubuntu 18.04
Demo Code
public async Task We_should_be_able_to_connect_and_list_files()
{
var client = new FtpClient("myhost", "user", "pass");
client.EncryptionMode = FtpEncryptionMode.Explicit;
client.SslProtocols = SslProtocols.Tls;
client.ValidateCertificate += (c, e) => { e.Accept = true; };
await client.ConnectAsync();
var items = await client.GetListingAsync("/");
Assert.NotEmpty(items);
}
Exception
System.IO.IOException : Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
at System.Net.Security.SslState.ThrowIfExceptional()
at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__46_2(IAsyncResult iar)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at FluentFTP.FtpSocketStream.ActivateEncryptionAsync(String targethost, X509CertificateCollection clientCerts, SslProtocols sslProtocols)
at FluentFTP.FtpClient.OpenPassiveDataStreamAsync(FtpDataConnectionType type, String command, Int64 restart)
at FluentFTP.FtpClient.OpenDataStreamAsync(String command, Int64 restart)
at FluentFTP.FtpClient.GetListingAsync(String path, FtpListOption options)
FluentFTP Log
...
# GetListingAsync("/", Auto)
Command: TYPE I
Response: 200 Type set to I
# OpenPassiveDataStreamAsync(AutoPassive, "MLSD /", 0)
Command: EPSV
Response: 229 Entering Extended Passive Mode (|||50992|)
Status: Connecting to ***:50992
Command: MLSD /
Response: 150 Opening data channel for directory listing of "/"
Status: Disposing FtpSocketStream...
What are we doing wrong?