【问题标题】:Error 550: the specified network name is no longer available when download file from ftp server with C#错误 550:使用 C# 从 ftp 服务器下载文件时,指定的网络名称不再可用
【发布时间】:2020-02-11 17:15:11
【问题描述】:

我正在编写一个应用程序 C# 以使用 Ftpwebrequest 从 ftp 服务器下载文件。我使用 ftp 服务器进行了测试,我的应用程序运行良好。但是当它在真实系统中运行时(ftp 服务器运行 windows server 2008),它会抛出异常:错误 550:指定的网络名称不再可用。有谁知道如何解决这个问题?谢谢。

【问题讨论】:

  • 没有任何代码,我们只能猜测 - 但我的猜测是在您的代码或设置中的某个位置,您指的是在您的开发环境中存在但在生产环境中无法访问的网络名称。我建议您发布您的代码并准确说明发生错误的位置。
  • 你看到我的代码了吗?
  • Ftp 服务器使用端口:66、68、88...,而不是默认端口。它们会导致错误吗?
  • 在您的代码不起作用的计算机上,您是否尝试过使用相同的凭据手动登录 ftp 服务器(例如通过浏览器或其他 FTP 客户端)。还要检查防病毒和这篇文章:stackoverflow.com/questions/44107643/…
  • 我尝试使用 File zilla 客户端和窗口资源管理器连接到 ftp 服务器。他们成功连接。

标签: c# ftpwebrequest


【解决方案1】:

对不起,我忘了发布我的代码:

public static bool TestConnection(string IPAdd, string port, string username, string password)
    {
        try
        {
            var downloadRequest = (FtpWebRequest)WebRequest.Create(@"ftp://" + IPAdd + ":" + port);
            downloadRequest.Credentials = new NetworkCredential(username, password);
            downloadRequest.Method = WebRequestMethods.Ftp.ListDirectory;

            var ftpWebResponse = (FtpWebResponse)downloadRequest.GetResponse();
            ftpWebResponse.Close();
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    • 2016-01-13
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    相关资源
    最近更新 更多