简体   繁体   English

FluentFTP - 连接时出错“尝试从套接字流中读取数据超时!”

[英]FluentFTP - Getting error while connecting “Timed out trying to read data from the socket stream!”

Getting 入门

Timed out trying to read data from the socket stream! 尝试从套接字流中读取数据超时!

when connecting to FTP using FluentFTP. 使用FluentFTP连接到FTP时。

Below is the source code which I am using to connect: 以下是我用来连接的源代码:

Console.WriteLine("Configuring FTP to Connect to {0}", hostname);
ftp = new FtpClient(hostname,port,new NetworkCredential(username,password));               
ftp.ConnectTimeout = 600000;               
ftp.ReadTimeout = 60000;
ftp.EncryptionMode = FtpEncryptionMode.Explicit;
ftp.SslProtocols = System.Security.Authentication.SslProtocols.Tls;
ftp.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
ftp.Connect();
Console.WriteLine("Connected to {0}", hostname);

ftp.SetWorkingDirectory(foldername);
Console.WriteLine("Changed directory to {0}", foldername);
void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
    // add logic to test if certificate is valid here
    e.Accept = true;
}

FileZilla log file for successful connectivity. FileZilla日志文件,用于成功连接。 I am able to connect the location via FileZilla. 我可以通过FileZilla连接位置。 Snippet of log is below: 日志片段如下:

2017-12-08 13:34:33 17672 1 Status: Connecting to xx.xx.xx.xx:990...
2017-12-08 13:34:33 17672 1 Status: Connection established, initializing TLS...
2017-12-08 13:34:33 17672 1 Status: Verifying certificate...
2017-12-08 13:35:06 17672 1 Status: TLS connection established, waiting for welcome message...
2017-12-08 13:35:06 17672 1 Response: 220-Microsoft FTP Service
2017-12-08 13:35:06 17672 1 Status: Invalid character sequence received, disabling UTF-8. Select UTF-8 option in site manager to force UTF-8.
2017-12-08 13:35:06 17672 1 Response:     Warning: This IT system is restricted to company authorised users only, including authorised third parties. Unauthorised access or use is a violation of Company’s policies and potentially the law. 
2017-12-08 13:35:06 17672 1 Response:     
2017-12-08 13:35:06 17672 1 Response: 220 Our IT systems may be monitored for administrative and security reasons. By proceeding, you acknowledge that you have read and understood this notice and that you consent to the monitoring. [ftps0]
2017-12-08 13:35:06 17672 1 Command: USER ftp_usr_comp_ext
2017-12-08 13:35:06 17672 1 Response: 331 Password required
2017-12-08 13:35:06 17672 1 Command: PASS ****************
2017-12-08 13:35:06 17672 1 Response: 230 User logged in.
2017-12-08 13:35:06 17672 1 Command: SYST
2017-12-08 13:35:06 17672 1 Response: 215 Windows_NT
2017-12-08 13:35:06 17672 1 Command: FEAT
2017-12-08 13:35:06 17672 1 Response: 211-Extended features supported:
2017-12-08 13:35:06 17672 1 Response:  LANG EN*
2017-12-08 13:35:06 17672 1 Response:  UTF8
2017-12-08 13:35:06 17672 1 Response:  AUTH TLS;TLS-C;SSL;TLS-P;
2017-12-08 13:35:06 17672 1 Response:  PBSZ
2017-12-08 13:35:06 17672 1 Response:  PROT C;P;
2017-12-08 13:35:06 17672 1 Response:  CCC
2017-12-08 13:35:06 17672 1 Response:  HOST
2017-12-08 13:35:06 17672 1 Response:  SIZE
2017-12-08 13:35:06 17672 1 Response:  MDTM
2017-12-08 13:35:06 17672 1 Response:  REST STREAM
2017-12-08 13:35:06 17672 1 Response: 211 END
2017-12-08 13:35:06 17672 1 Command: PBSZ 0
2017-12-08 13:35:07 17672 1 Response: 200 PBSZ command successful.
2017-12-08 13:35:07 17672 1 Command: PROT P
2017-12-08 13:35:07 17672 1 Response: 200 PROT command successful.
2017-12-08 13:35:07 17672 1 Status: Logged in
2017-12-08 13:35:07 17672 1 Status: Retrieving directory listing of "/Prod/Outbound"...
2017-12-08 13:35:07 17672 1 Command: CWD /Prod/Outbound
2017-12-08 13:35:07 17672 1 Response: 250 CWD command successful.

Stack Trace: 堆栈跟踪:

   at FluentFTP.FtpSocketStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at FluentFTP.FtpSocketStream.ReadLine(Encoding encoding)
   at FluentFTP.FtpClient.GetReply()
   at FluentFTP.FtpClient.Handshake()
   at FluentFTP.FtpClient.Connect()
   at ASOSSFTP.DownloadFile.DownloadFileFromFTP()

In FileZilla, you are connecting to implicit FTPS port 990. 在FileZilla中,您将连接到隐式 FTPS端口990。

If you also use this port in C#, you cannot use FtpEncryptionMode.Explicit . 如果您还在C#中使用此端口,则无法使用FtpEncryptionMode.Explicit

Use FtpEncryptionMode.Implicit . 使用FtpEncryptionMode.Implicit

Though you better connect to port 21 and keep using FtpEncryptionMode.Explicit , if that port is available. 虽然您最好连接到端口21并继续使用FtpEncryptionMode.Explicit ,但该端口是否可用。

The following code is all you need to get FluentFtp (at least nuget (1.0.5824.34026) to use secure connection . 以下代码是获取FluentFtp(至少nuget(1.0.5824.34026)使用安全连接所需的全部代码)。

        FtpClient fclient = new FtpClient(hostname, username, password); // or set Host & Credentials

        fclient.EncryptionMode = FtpEncryptionMode.Implicit;  
        fclient.SslProtocols = SslProtocols.Tls12;

        //client.Port = 990;  // Not required - probably gives you exceptions if you try to set it. 

        fclient.Connect();
        fclient.UploadFile(@"C:\tmp\a.txt", "big.txt");

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 处理来自套接字 stream 的数据时,集合被修改错误 - Collection was modified error while processing data from socket stream 连接到 FTP 端口 21 时,SSH.NET 出现“套接字读取操作已超时”异常 - "Socket read operation has timed out" exception with SSH.NET when connecting to FTP port 21 从表中读取数据时出现错误 - Getting Error while read the data from table 在尝试从Web API获取JSON数据的教程时,我偶然发现了此错误,而视频没有遇到此错误 - Trying out a tutorial for getting JSON data from a web API and I stumbled on this error while the video did not encounter this error 尝试从数据读取器读取值时发生转换错误 - Casting error while trying to read value from data reader 从Facebook得到响应正在超时 - getting response from Facebook is getting timed out 尝试使用C#中的ODbc读取MSysObjects中的数据,但没有获得权限错误 - Trying to read data out of MSysObjects with ODbc in C#, but getting no permission error 尝试从内部Zip文件(另一个Zip中的Zip)获取流时,获得“无法将其作为Zip文件读取”异常 - Getting a “Cannot Read That as a Zip File” Exception while trying to get a stream from an Inner Zip File (a Zip within another Zip) 为什么我收到错误“您的请求已超时。 请重试请求”一次? - Why am I getting the error “your request is timed out. please retry the request” once in a while? 为什么在尝试从XML文件读取数据时出现Null Referenfe异常? - Why am I getting Null Referenfe exception while trying to read data from XML file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM