C# SslStream.AuthenticateClient-无法在发送时立即完成非阻塞套接字操作
我当前正在尝试使用TcpClient连接到FTP服务器。 对于使用FTPS作为协议,我通过NetworkStream将其处理为一个单独的方法,该方法使用该方法创建SslStream,然后调用SslStream.AuthenticateTasClient并引发异常,发送时无法立即完成非阻塞套接字操作。实际流由TcpClient.GetStream-method初始化。 实际上,源代码来自Biko库,您可以在此处找到该部分: 所以,我的问题是,我如何修改源代码,使这个异常不再抛出?我无法删除身份验证,但错误也应该消失。是什么导致了这个错误 提前感谢。已修复。 我刚刚更新到库的更新版本。这个问题是由线程问题引起的,作者通过添加锁关键字解决了这个问题C# SslStream.AuthenticateClient-无法在发送时立即完成非阻塞套接字操作,c#,.net,sockets,ftp,C#,.net,Sockets,Ftp,我当前正在尝试使用TcpClient连接到FTP服务器。 对于使用FTPS作为协议,我通过NetworkStream将其处理为一个单独的方法,该方法使用该方法创建SslStream,然后调用SslStream.AuthenticateTasClient并引发异常,发送时无法立即完成非阻塞套接字操作。实际流由TcpClient.GetStream-method初始化。 实际上,源代码来自Biko库,您可以在此处找到该部分: 所以,我的问题是,我如何修改源代码,使这个异常不再抛出?我无法删除身份验证
private Stream CreateSslStream(Stream stream)
{
// create an SSL or TLS stream that will close the client's stream
SslStream ssl = new SslStream(stream, true, new RemoteCertificateValidationCallback(secureStream_ValidateServerCertificate), null);
// choose the protocol
SslProtocols protocol = SslProtocols.None;
switch (_securityProtocol)
{
case FtpSecurityProtocol.Tls1OrSsl3Explicit:
case FtpSecurityProtocol.Tls1OrSsl3Implicit:
protocol = SslProtocols.Default;
break;
case FtpSecurityProtocol.Ssl2Explicit:
case FtpSecurityProtocol.Ssl2Implicit:
protocol = SslProtocols.Ssl2;
break;
case FtpSecurityProtocol.Ssl3Explicit:
case FtpSecurityProtocol.Ssl3Implicit:
protocol = SslProtocols.Ssl3;
break;
case FtpSecurityProtocol.Tls1Explicit:
case FtpSecurityProtocol.Tls1Implicit:
protocol = SslProtocols.Tls;
break;
default:
throw new FtpSecureConnectionException(String.Format("unexpected FtpSecurityProtocol type '{0}'", _securityProtocol.ToString()));
}
// note: the server name must match the name on the server certificate.
try
{
// authenticate the client
ssl.AuthenticateAsClient(_host, _clientCertificates, protocol, true);
}
catch (AuthenticationException authEx)
{
throw new FtpAuthenticationException("Secure FTP session certificate authentication failed.", authEx);
}
return ssl;
}