描述
当使用 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...
我们做错了什么?