获取FTP上的所有文件名,保存到List<String>中
FtpWebRequest reqFTP; List<String> tempFile = new List<string>(); List<String> tempXml = new List<string>(); reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uristring)); //ftppath + "/" + filename)); reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(_account, _pwd); reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; WebResponse response = reqFTP.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8")); //获取职位 string line = reader.ReadLine(); //遍历所有文件,把xml和文件夹分别放入相应数组里面 while (line != null) { if (line.ToUpper().EndsWith(".XML")) { tempXml.Add(line.ToUpper()); } else tempFile.Add(line); line = reader.ReadLine(); } reader.Close(); response.Close();
更多前端内容请访问个人博客:殷路辉的个人博客