/// <summary> /// 下载报文 /// </summary> /// <param name="type"></param> /// <param name="localDir"></param> /// <param name="filePath"></param> /// <returns></returns> public override string DownResultFileData(string localDir, string filePath) { FtpUtil ftp = new FtpUtil(config.GZJCIcpInfoTrade.FtpUrl, config.GZJCIcpInfoTrade.FtpName, config.GZJCIcpInfoTrade.FtpPassword); string msg = ""; ftp.DownloadFile(config.GZJCIcpInfoTrade.FtpUrl + "out/" + filePath, localDir, out msg); return(msg); }
public void TestMethod3() { // bool isCon = FtpUtil.Connect("ftp://192.168.123.128:21", "root", "root"); bool result = FtpUtil.DownloadFile("E://Xiaomi/", "01.jpg", "ftp://192.168.123.128:21/test", "root", "root"); if (result) { } }
/// <summary> /// 下载报文 /// </summary> /// <param name="type"></param> /// <param name="localDir"></param> /// <param name="filePath"></param> /// <returns></returns> public override string DownResultFileData(OrderStatus.商检反馈报文类型 type, string localDir, string filePath) { FtpUtil ftp = new FtpUtil(config.NSIcpInfo.FtpUrl, config.NSIcpInfo.FtpName, config.NSIcpInfo.FtpPassword); string msg = ""; switch (type) { case Hyt.Model.WorkflowStatus.OrderStatus.商检反馈报文类型.商品检查: ftp.DownloadFile(config.NSIcpInfo.FtpUrl + "4200.IMPBA.SWBCARGOBACK.REPORT/out/" + filePath, localDir, out msg); //ftp.DeleteFile(ftpUri + "4200.IMPBA.SWBCARGOBACK.REPORT/out/" + filePath); break; case Hyt.Model.WorkflowStatus.OrderStatus.商检反馈报文类型.商品订单: ftp.DownloadFile(config.NSIcpInfo.FtpUrl + "4200.IMPBA.SWBEBTRADE.REPORT/out/" + filePath, localDir, out msg); //ftp.DeleteFile(ftpUri + "4200.IMPBA.SWBEBTRADE.REPORT/out/" + filePath); break; case Hyt.Model.WorkflowStatus.OrderStatus.商检反馈报文类型.商品审核报文: ftp.DownloadFile(config.NSIcpInfo.FtpUrl + "4200.IMPBA.SWBCARGOBACK.AUDIT/out/" + filePath, localDir, out msg); //ftp.DeleteFile(ftpUri + "4200.IMPBA.SWBCARGOBACK.AUDIT/out/" + filePath); break; } return(msg); }
/// <summary> /// 下载xml文件 /// 2015-10-09 王耀发 创建 /// </summary> /// <param name="RequestText"></param> public static string DownloadXmlFile(string RequestText) { //RequestText = "{\"FileName\":\"880020201510101023450000.xml\"}"; var jsonObject = JObject.Parse(RequestText); string FileName = jsonObject["FileName"].ToString(); string _ftpImageServer = ApiConfig.FtpUrl + "DOWNLOAD/"; string _ftpUserName = ApiConfig.FtpUserName; string _ftpPassword = ApiConfig.FtpPassword; FtpUtil ftp = new FtpUtil(_ftpImageServer, _ftpUserName, _ftpPassword); string msg = ""; ftp.DownloadFile(_ftpImageServer + FileName, HttpContext.Current.Server.MapPath("~/Xml"), out msg); StreamReader objReader = new StreamReader(HttpContext.Current.Server.MapPath("~/Xml") + "\\" + FileName); string sLine = objReader.ReadToEnd(); objReader.Close(); //删除对应文件 if (File.Exists(HttpContext.Current.Server.MapPath("~/Xml") + "\\" + FileName)) { File.Delete(HttpContext.Current.Server.MapPath("~/Xml") + "\\" + FileName); } return(AESHelper.Decrypt(sLine)); }
public static void ComPressProductPic() { bool IsFtpServer = bool.Parse(ConfigurationManager.AppSettings["IsFtpServer"]); int Num_i = Convert.ToInt16(ConfigurationManager.AppSettings["NumOnceDeal"]); int SleepTime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SleepTime"]); IList <ConfigPicComPressEntity> picconfig = ConfigPicComPressBLL.Instance.GetConfigListByPicSource((int)SourcePicTypeEnum.Product); while (true) { IList <ProductStylePicsEntity> _piclist = new List <ProductStylePicsEntity>(); _piclist = ProductStylePicsBLL.Instance.GetStylePicsNoComPress(Num_i); if (_piclist != null && _piclist.Count > 0) { //ParallelOptions po = new ParallelOptions(); //po.MaxDegreeOfParallelism = 15; //最多并发50个任务 string FtpServerPath = ""; string ImagePath = ""; if (IsFtpServer) { FtpServerPath = ConfigurationManager.AppSettings["FtpServerPathPrefix"].ToString(); } ImagePath = ConfigurationManager.AppSettings["ImagePath"].ToString(); if (picconfig != null && picconfig.Count > 0) { string allids = "0"; string successids = "0"; string failids = "0"; string error = "1"; foreach (ProductStylePicsEntity o in _piclist) { allids = allids + "," + o.Id.ToString(); string filepath = FtpServerPath + ImagePath.Replace("/", "\\") + o.PicUrl.Replace("/", "\\") + "." + o.PicSuffix; try { if (IsFtpServer) { foreach (ConfigPicComPressEntity en in picconfig) { Image sourceImg = Image.FromFile(filepath); ImageFormat _imgf = sourceImg.RawFormat; string savepath = FtpServerPath + ImagePath.Replace("/", "\\") + o.PicUrl.Replace("/", "\\") + en.PicName + "." + o.PicSuffix; int Width = en.Width; int Height = en.Height; using (Image ThumbImgl = PicTool.GetImageThumb(sourceImg, Width, Height)) { ThumbImgl.Save(savepath, _imgf); ThumbImgl.Dispose(); } sourceImg.Dispose(); } } else { FtpUtil _ftp = new FtpUtil(); string downloadpath = ImagePath + o.PicUrl + "." + o.PicSuffix; byte[] _byt = _ftp.DownloadFile(downloadpath); Image sourceImg = PicTool.GetImageByBytes(_byt); foreach (ConfigPicComPressEntity en in picconfig) { int Width = en.Width; int Height = en.Height; string uploadpath = ImagePath + o.PicUrl + en.PicName + "." + o.PicSuffix; using (Image ThumbImgl = PicTool.GetImageThumb(sourceImg, Width, Height)) { byte[] _byts = PicTool.GetByteByImage(ThumbImgl); _ftp.UploadFile(uploadpath, _byts, false); ThumbImgl.Dispose(); } } sourceImg.Dispose(); } successids = successids + "," + o.Id.ToString(); } catch (Exception ex) { LogUtil.Log(ex); failids = failids + "," + o.Id.ToString(); } } ProductStylePicsBLL.Instance.ComPressComplete(allids, successids, failids); } Thread.Sleep(SleepTime); } } }