.Net FtpWebRequest有时会失败 [英] .Net FtpWebRequest fails sometimes
本文介绍了.Net FtpWebRequest有时会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用列表中的FtpWebRequest文件的细节,但很频繁失败并引发WebException并显示错误没有登录530用户。
I try to list file details using FtpWebRequest but very frequently it fails with a WebException and shows error 530 User not logged in.
这怎么可能,这一些时间使用相同的凭据?
How is this possible, that it works some of the time using the same credentials?
摘自代码:
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpuri));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(userName, password);
string[] downloadFiles = new string[0];
reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
downloadFiles = reader.ReadToEnd().Replace("\r\n", "¤").Split('¤');
reader.Close();
response.Close();
推荐答案
尝试设置
reqFTP.KeepAlive = false;
并且可能如果上述不起作用
and possibly if the above does not work
reqFTP.UsePassive = false;
我发现将这些设置为false减少了此错误的发生(这是由FTP服务器)很大。
I found that setting these to false reduced the occurrences of this error (which is generated by the FTP server) considerably.
这篇关于.Net FtpWebRequest有时会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文