1. 在應(yīng)用。NET 訪問(wèn)FTP的Response來(lái)返回時(shí),出現(xiàn)了如下錯(cuò)誤。
2. 參考如下MSDN 和一些網(wǎng)絡(luò)資源,嘗試后解決了此問(wèn)題.
> Ftp GetFileSize randomly throws FTP error 503 (Bad Sequence of Commands)
>FtpWebRequest re-sending USER and PASS commands half way through download loop
3. 問(wèn)題是在此處應(yīng)用此個(gè)FTP Request 之前曾經(jīng)使用些地址創(chuàng)建了一個(gè)登錄Session, 所以在后面同一地址會(huì)話建立時(shí)會(huì)有這個(gè)異常報(bào)告。
The remote server returned an error: (503) Bad sequence of commands.
解決辦法就是將 request 對(duì)象的 KeepAlive 設(shè)為 False,其后基于同一IP創(chuàng)建的Session將不會(huì)拋出異常了。
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(sUnixURL));//"ftp://" + "10.2.159.69" + "/" + fileInf.Name));
reqFTP.Credentials = new NetworkCredential("dwei", "Admin98");
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.KeepAlive = false; // If keepalive is true will make the same IP request response lead to failed !
FileStream outputStream = new FileStream(FILE_NAME, FileMode.Create);
// Create the writer for data.
BinaryWriter w = new BinaryWriter(outputStream);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();