说明
使用FluentFTP连接到FileZilla FTPS服务器时,尝试列出文件时会显示System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
。
我们可以建立初始连接,也可以登录,但是当FluentFTP尝试通过EPSV建立数据连接时,该错误会出错。
到目前为止,我们的研究似乎表明TLS恢复失败。 FTPS服务器坚持通过数据连接从控制连接恢复TLS会话,这似乎失败了。奇怪的是,这仅发生在Linux或WSL上的dotnetcore上。在Windows上的dotnetcore上一切正常。
版本: DotNetCore 2.1.5 FluentFTP 19.2.2
操作系统 Ubuntu 18.04 / Windows 10 WSL Ubuntu 18.04
演示代码
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);
}
例外
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日志
...
# 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...
我们在做什么错了?