0
我想获得一个服务器上的文件列表下载文件
CODE:
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));
这是抛出一个System.NotSuportedException on reqFTP.Content and reqFTP.PreAuthenticate部分我想。
尝试'reqFTP.EnableSsl = false;'? –
仅供参考 - 您的最终FTP网址中有前后斜杠。 –