获取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();

 

posted @ 2012-08-17 11:11  Alec-Yin  阅读(3229)  评论(0编辑  收藏  举报
更多前端博客,访问:http://lhyin.com