[英]Download files from a server
我正在尝试获取服务器上的文件列表
码:
string ftpUserID = "user";
string ftpPassword = "password";
string ftpServerIP = "192.###.###.###";
string remoteDirectory = @"\Update\UpdateTest";
string localDirectory = @"C:\Updates";
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + remoteDirectory));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
reqFTP.EnableSsl = true;
reqFTP.Proxy = null;
reqFTP.KeepAlive = true;
reqFTP.UsePassive = true;
response = reqFTP.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
return result.ToString().Split('\n');
我不断收到WebException错误,提示“无法连接到远程服务器”
这是由于出现以下错误:
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + remoteDirectory));
我认为这在reqFTP.Content和reqFTP.PreAuthenticate部分上引发 System.NotSuportedException 。
您提到,尽管在代码中不可见,但是您使用了PreAuthenticate
。 FTP不支持此功能。
提供PreAuthenticate
属性仅是为了与msdn的WebRequest和WebResponse类的其他实现兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.