private bool DownloadFTP(string filePath, string ftpServerIP, string ftpUserID, string ftpPassword) { FtpWebRequest reqFTP; try { BLL.gigade.Common.FTP FTP = new Common.FTP(ftpServerIP, ftpUserID, ftpPassword); List<string> fileList = FTP.GetFileList(); foreach (string item in fileList) { string uri = string.Format("{0}/{1}", ftpServerIP, item); FileStream outputStream = new FileStream(filePath + "\\" + item, FileMode.Create); reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));// 根据uri创建FtpWebRequest对象 reqFTP.Method = WebRequestMethods.Ftp.DownloadFile; reqFTP.UseBinary = true; reqFTP.KeepAlive = false; reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); Stream ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int bufferSize = 2048; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream.Read(buffer, 0, bufferSize); while (readCount > 0) { outputStream.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); } ftpStream.Close(); outputStream.Close(); response.Close(); } } catch (Exception ex) { throw new Exception("ReceiveStatusFromTCatMgr-->DownloadFTP-->" + ex.Message); } return true; }