我正在使用以下代码从FTP服务器下载文件。但无论如何,我总是会收到超时信息。
ftpo = System.Net.WebRequest::Create("ftp://myserver.com/subFolder/filename.txt");
request = ftpo;
credential = new System.Net.NetworkCredential(_user, _password);
request.set_Credentials(credential);
request.set_KeepAlive(false);
request.set_Method(_ftpMethod);
request.set_UsePassive(true);
request.set_UseBinary(true);
request.set_Timeout(600000);
request.set_ReadWriteTimeout(600000);
ftpResponse = request.GetResponse();
response = ftpResponse;
reader = new System.IO.StreamReader(response.GetResponseStream());
if(reader)
{
readString = reader.ReadToEnd();
}
if(readString)
{
writer = new System.IO.StreamWriter(_destination);
writer.Write(readString);
writer.Flush();
writer.Close();
}
错误消息
操作已经超时。
该文件为9kB。通过Filezilla下载它需要不到1秒。超时设置为10分钟。
导致此消息的原因是什么? 关于如何调试它的任何想法(我无法访问FTP服务器)。
更新: 在C#中,相同的代码运行良好。
FtpWebRequest ftpRequest;
var request = WebRequest.Create("ftp://server.com/folder/file.txt");
ftpRequest = (FtpWebRequest) request;
request.Credentials = new NetworkCredential("", "");
request.Method = "RETR";
ftpRequest.KeepAlive = false;
ftpRequest.UsePassive = true;
ftpRequest.UseBinary = true;
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var result = "";
if(reader != null)
{
result = reader.ReadToEnd();
var writer = new StreamWriter(@"C:\temp\outfile.txt");
writer.Write(result);
writer.Flush();
writer.Close();
}
答案 0 :(得分:0)
尝试使用或采用此方法:
PB01->setCheckable(true);