我正在编写应用程序C#,以使用Ftpwebrequest从ftp服务器下载文件。我使用ftp服务器进行了测试,我的应用程序运行正常。但是,当它在实际系统中运行(ftp服务器运行Windows Server 2008)时,它将引发异常:错误550:指定的网络名称不再可用。有人知道如何解决这个问题吗?谢谢。
答案 0 :(得分:0)
对不起,我忘记发布我的代码:
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;
}
}