private void DownloadFile_ftp(string LocalUrl, string FileAddress_ftp) { string FtpServer = ConfigurationManager.AppSettings["FtpServer"]; string FtpPort = ConfigurationManager.AppSettings["FtpPort"]; string FtpUser = ConfigurationManager.AppSettings["FtpUser"]; string FtpPassword = ConfigurationManager.AppSettings["FtpPassword"]; FtpWeb ftp = new FtpWeb(FtpServer + ":" + FtpPort, "PRS_ProcessFigure", FtpUser, FtpPassword); var filename = FileAddress_ftp.Substring(FileAddress_ftp.LastIndexOf('/') + 1); ftp.Download(LocalUrl, filename); }
private void Btn_UploadFile_Click(object sender, EventArgs e) { ILog log = LogManager.GetLogger("ErrorName"); try { string FtpServer = ConfigurationManager.AppSettings["FtpServer"]; string FtpPort = ConfigurationManager.AppSettings["FtpPort"]; string FtpUser = ConfigurationManager.AppSettings["FtpUser"]; string FtpPassword = ConfigurationManager.AppSettings["FtpPassword"]; FtpWeb ftp = new FtpWeb(FtpServer + ":" + FtpPort, "PRS_ProcessFigure", FtpUser, FtpPassword); var FileList = lst_filelist.Items.Count; if (FileList == 0) { MessageBox.Show("请选择需要上传的工艺图纸!", "提示"); return; } if (lblFigureNumber.Text == "图号:") { MessageBox.Show("图号为空!", "提示"); return; } Task.Run(() => { long TotalBytes = 0; var list = new List <string>(); foreach (string item in lst_filelist.Items) { FileInfo fileInfo = new FileInfo(item); TotalBytes += fileInfo.Length; list.Add(item); } prs_bar.Value = 0; FtpWeb.file_jd = 0; int id = ID; log.Info("web端传入的PRS_ProcessBom的ID:" + id.ToString()); string url = string.Format(@"http://{0}/api/Mms/MES_BN_ProductProcessRoute/GetUpdateProcessFigureIsEnableByProcessBomID?processBomID=" + id, Program.API); log.Info("web端改变IsEnable的webapi地址:" + url); string result = Helpers.HttpHelper.GetJSON(url); foreach (string item in list) { string ftp_url = "", file_name = ""; string num = DateTime.Now.ToString("yyyyMMddHHmmssfff"); ftp.Upload(num, prs_bar, TotalBytes, item, out ftp_url, out file_name); string url1 = string.Format(@"http://{0}/api/Mms/Home/PostUpdate3", Program.API); log.Info("web端插入上传数据的webapi地址:" + url1); string result1 = Helpers.HttpHelper.PostJSON(url1, new { id = id, docName = file_name, fileName = num, filePath = ftp_url }); log.Info("web端插入上传数据的webapi返回内容:" + result1); this.lst_filelist.Items.Remove(item); if (FtpWeb.file_jd == TotalBytes) { hubProxy.Invoke("finishUpload", UserCode).Wait(); lblFigureNumber.Text = "图号:"; MessageBoxShow(this, "图纸已上传完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } }); } catch (Exception ex) { log.Error(ex.Message); } }