110,572
社区成员
发帖
与我相关
我的任务
分享
FtpWebRequest checkRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(_upLoadPath));
checkRequest.Method = WebRequestMethods.Ftp.ListDirectory;
checkRequest.UseBinary = true;
checkRequest.Credentials = new NetworkCredential(_userName, _password);
FtpWebResponse response = (FtpWebResponse)checkRequest.GetResponse();
StreamReader sw = new StreamReader(response.GetResponseStream());
List<string> files = new List<string>();
string line = sw.ReadLine();
while (line != null)
{
files.Add(line.Substring(line.IndexOf("/") + 1));
line = sw.ReadLine();
}
sw.Close();
response.Close();
checkRequest.Method = WebRequestMethods.Ftp.ListDirectory;这句就是获取所以文件名
files.Add(line.Substring(line.IndexOf("/") + 1));把获取到的文件名去除路径后存储到一个List中(D:/A/1.txt => 1.txt)