我做了一個FTP服務器的設置(基於ubuntu \ vsftpd)。帶有SSL TLS的System.Net.FtpClient - 超時嘗試連接
我從互聯網上連接這個ftp服務器,所以我激活了服務器中的SSL安全功能。
爲了檢查一切正常,我使用FileZiLla進行了測試 - >它正在工作。 日誌(從FileZilla中):
Status: Connecting to ****:21...
Status: Connection established, waiting for welcome message...
Response: 220 (vsFTPd 3.0.2)
Command: AUTH TLS
Response: 234 Proceed with negotiation.
Status: Initializing TLS...
Status: Verifying certificate...
Command: USER ****
Status: TLS/SSL connection established.
Response: 331 Please specify the password.
Command: PASS ********
Response: 230 Login successful.
Command: SYST
Response: 215 UNIX Type: L8
Command: FEAT
Response: 211-Features:
Response: AUTH SSL
Response: AUTH TLS
Response: EPRT
Response: EPSV
Response: MDTM
Response: PASV
Response: PBSZ
Response: PROT
Response: REST STREAM
Response: SIZE
Response: TVFS
Response: UTF8
Response: 211 End
Command: OPTS UTF8 ON
Response: 200 Always in UTF8 mode.
Command: PBSZ 0
Response: 200 PBSZ set to 0.
Command: PROT P
Response: 200 PROT now Private.
Status: Connected
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/home/****"
Command: TYPE I
Response: 200 Switching to Binary mode.
Command: PASV
Response: 227 Entering Passive Mode (*,*,*,*,*,*).
Command: LIST
Response: 150 Here comes the directory listing.
Response: 226 Directory send OK.
Status: Directory listing successful
要回到我的C#代碼... 我想我的服務器用下面的代碼,它基於System.Net.FtpClient連接:
public PageDownloader()
{
this.Client = new FtpClient();
this.Client.Host = FTP_HOST;
this.Client.Port = 21;
this.Client.Credentials = new NetworkCredential(FTP_USER, FTP_PASS);
this.Client.DataConnectionType = FtpDataConnectionType.PASV;
this.Client.EncryptionMode = FtpEncryptionMode.Explicit;
this.Client.ValidateCertificate += Client_ValidateCertificate;
this.Client.Connect(); // Exception- System.TimeoutException: Timed out trying to connect!
}
void Client_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
// Never rich here
e.Accept = true; // Allow all - just for testing...
}
我有這個例外:
System.TimeoutException:超時嘗試連接!在在 System.Net.FtpClient.FtpClient.Connect() System.Net.FtpClient.FtpSocketStream.Connect(字符串主機,端口的Int32, FtpIpVersion ipVersions)
有人知道它爲什麼會發生?爲什麼我應該檢查?
你解決這個問題?與ftps有同樣的問題。 – sangam