日期:2014-05-18 浏览次数:20916 次
/// <summary> /// 根据ftp路径返回目录下的文件名称 不带扩展名 /// </summary> /// <param name="ftpDir"></param> /// <param name="userName"></param> /// <param name="passWord"></param> /// <returns></returns> public static ArrayList GetFileNames(string ftpDir, string userName, string passWord) { var fileNames = new ArrayList(); var reqFtp = (FtpWebRequest)WebRequest.Create(new Uri(ftpDir)); reqFtp.UsePassive = false; reqFtp.UseBinary = true; //reqFTP.EnableSsl = true;//加密方式传送数据 FTP 服务器要支持 reqFtp.Credentials = new NetworkCredential(userName, passWord); reqFtp.Method = WebRequestMethods.Ftp.ListDirectory; var response = (FtpWebResponse)reqFtp.GetResponse(); var reader = new StreamReader(response.GetResponseStream(), Encoding.Default); string fileName = reader.ReadLine(); while (fileName != null) { fileNames.Add(Path.GetFileNameWithoutExtension(fileName)); fileName = reader.ReadLine(); } reader.Close(); response.Close(); //var fileNames = reader.ReadToEnd(); reader.Close(); response.Close(); return fileNames; }