C#.Net遍历远程文件夹下的所有文件 FTP
C#.Net遍历远程文件夹下的所有文件
private string GetFileNames(string URI) {
WebClient wClient = new WebClient();
FtpWebRequest FtpClient;
Uri uri = new Uri(URI);
FtpClient = (FtpWebRequest)WebRequest.Create(uri);
FtpClient.Credentials.GetCredential(uri, "user").UserName = "zwc";
FtpClient.Credentials.GetCredential(uri, "user").Password = "12345";
FtpClient.Credentials.GetCredential(uri, "user").Domain = "";
FtpClient.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)FtpClient.GetResponse();
StreamReader stream = new StreamReader(response.GetResponseStream());
return stream.ReadToEnd();
}