首页 > 其他 > 详细

FTP文件下载

时间:2014-03-12 16:42:33      阅读:498      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
using EnterpriseDT.Net.Ftp;

///
<summary> /// 下载FTP文件 /// </summary> /// <param name="ftpInfo">FTP类</param> /// <returns></returns> public void DownFtpFiles() { #region while (true) { List<string> fileList = new List<string>(); EnterpriseDT.Net.Ftp.FTPClient ftpClient = new EnterpriseDT.Net.Ftp.FTPClient(); try { System.Threading.Thread.Sleep(10000); log.Info("开始登陆FTP服务器"); ftpClient.RemoteHost = ftpIP; ftpClient.Connect(); ftpClient.Login(ftpUserName, ftpPassword); ftpClient.TransferType = FTPTransferType.BINARY; //获得所有文件列表 GetFileList(ftpClient, ftpRoot, ref fileList); log.Info("FTP服务器共有" + fileList.Count + "个文件"); //开始下载文件 if (fileList != null && fileList.Count > 0) { string fileName = null; foreach (string fileUrl in fileList) { #region 判断文件是否已经下载过 fileName = fileUrl; if (fileName.StartsWith("url_") && fileName.ToLower().EndsWith(".dat")) { try { log.Info("开始下载," + fileUrl); ftpClient.Get(tempFileDir + "\\" + fileName, fileUrl); File.Move(tempFileDir + "\\" + fileName, downloadFileDir + "\\" + fileName); //记录到已下载的列表中 this.AppendDownloaded(fileUrl); //删除远程文件 ftpClient.Delete(fileUrl); log.Info("下载成功," + fileUrl); } catch (Exception exp) { log.Info("下载或移动失败," + fileUrl + ",原因是:" + exp.ToString()); } } #endregion } } } catch (Exception exp) { log.Info("下载或移动失败,原因是:" + exp.ToString()); } finally { try { if (ftpClient.IsConnected) ftpClient.Quit(); } catch (Exception ex) { log.Info("关闭FTP连接异常,原因是:" + ex.ToString()); } } //System.Threading.Thread.Sleep(Tools.GetInt32(Tools.GetWebSetting("DOWNLOAD_INTERVAL"), 30) * 1000 * 60); } #endregion }
bubuko.com,布布扣

FTP文件下载,布布扣,bubuko.com

FTP文件下载

原文:http://www.cnblogs.com/ringwang/p/3596462.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!