【问题标题】:.Net FtpWebRequest fails sometimes.Net FtpWebRequest 有时会失败
【发布时间】:2010-12-06 06:21:31
【问题描述】:

我尝试使用 FtpWebRequest 列出文件详细信息,但它经常失败并出现 WebException 并显示错误 530 用户未登录。

这怎么可能,它有时使用相同的凭据工作?

代码摘录:

        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();

【问题讨论】:

  • 我遇到了这个确切的问题。当我已经连接到服务器一段时间后,它似乎更频繁地发生,然后我更改目录并做一个列表。
  • 您的问题类似于内置 Windows Explorer FTP(即:Internet Explorer 集成到 Explorer.exe)中的错误,在导航目录后它会“丢失”您的凭据并反复要求您登录.不过,我在使用 dotnet 时从未听说过这种行为。

标签: c# .net ftp ftpwebrequest


【解决方案1】:

尝试设置

reqFTP.KeepAlive = false;

如果上述方法不起作用,则可能

reqFTP.UsePassive = false;

我发现将这些设置为 false 可以大大减少此错误(由 FTP 服务器生成)的发生。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 2014-05-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 2011-08-10
    • 2016-06-21
    相关资源
    最近更新 更多