public override bool Validate(ref string msg) { bool bRet = false; string ip, port, userName, password, path; if (FtpWeb.GetFtpUrlInfo(m_PicSource, out ip, out port, out userName, out password, out path)) { string ipAndPort = string.Format("{0}:{1}", ip, port); m_ftpIP = ip; m_ftpPort = Convert.ToInt32(port); m_ftpUser = userName; m_ftpPass = password; m_ftpPath = path; try { m_FTPFileService = new FtpWeb(m_ftpIP + ":" + m_ftpPort, "", m_ftpUser, m_ftpPass); //m_FTPFileService.Open(); //m_FTPFileService.Login(); bRet = true; } catch (Exception ex) { msg = ex.Message; bRet = false; } } else { msg = "非法ftp地址"; } return(bRet); }
private static bool Download(string remoteDir, string localDir) { var ftp = new FtpWeb( DbFactory.FTPSetting.Server, DbFactory.FTPSetting.Port, DbFactory.FTPSetting.UserID, DbFactory.FTPSetting.Password); string[] files; if (!ftp.DirectoryListSimple(remoteDir, out files)) { return(false); } if (!Directory.Exists(localDir)) { Directory.CreateDirectory(localDir); } foreach (var file in files) { ftp.Download(remoteDir + file, localDir + file); } return(true); }
private void FtpDownload(M_MyJob myJob) { //文件路径 string filePath = Path.GetDirectoryName(myJob.FilePath).Replace("\\", "//"); //文件名 string fileName = Path.GetFileName(myJob.FilePath); //复制文件到系统路径 string copyPath = string.Format(@"{0}\SowerTestClient\Paper\Download\{1}_{2}", Application.StartupPath, PublicClass.StudentCode, fileName); //下载文件保存路径 string savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName); FtpWeb ftpWeb = CommonUtil.GetFtpWeb(); if (ftpWeb != null) { ftpWeb.Download(Globals.DownLoadDir, fileName, filePath, tsbBar, tsbMessage, "作业下载进度:"); } //复制作业到系统目录 File.Copy(savePath, copyPath, true); //删除下载文件 File.Delete(savePath); //设置已下载状态 dgvResult.SelectedRows[0].Cells["JobDownLoadState"].Value = "已下载"; tsbMessage.Text = "作业下载进度:"; tsbBar.Value = 0; //下载账套文件 if (ftpWeb != null && myJob.RequireEnvFile.ToLower() == "true" && myJob.IsUpload.ToLower() == "true" && cbIsDownAccount.Checked == true) { filePath = Path.GetDirectoryName(myJob.EnvFilePath).Replace("\\", "//"); fileName = myJob.EnvFileName; copyPath = string.Format(@"{0}\SowerTestClient\Paper\Account\{1}", Application.StartupPath, fileName); savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName); ftpWeb.Download(Globals.DownLoadDir, fileName, filePath, tsbBar, tsbMessage, "帐套下载进度:"); //复制作业到系统目录 DirFileHelper.Copy(savePath, copyPath); //删除临时下载文件 DirFileHelper.DeleteFile(savePath); tsbMessage.Text = "帐套下载进度:"; tsbBar.Value = 0; dgvResult.SelectedRows[0].Cells["AccountDownLoadState"].Value = "已下载"; } //下载视频文件 if (ftpWeb != null && myJob.IsUploadVideoFile == true && string.IsNullOrEmpty(myJob.VideoFilePath) == false && cbIsDownVideo.Checked == true) { filePath = Path.GetDirectoryName(myJob.VideoFilePath).Replace("\\", "//"); fileName = myJob.VideoFileName; copyPath = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}\", Application.StartupPath, PublicClass.StudentCode, DirFileHelper.GetFileNameNoExtension(myJob.VideoFilePath)); savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName); ftpWeb.Download(Globals.DownLoadDir, fileName, filePath, tsbBar, tsbMessage, "视频下载进度:"); //复制作业到系统目录 ZipFileTools.UnZipSZL(savePath, copyPath); //删除临时下载文件 DirFileHelper.DeleteFile(savePath); tsbMessage.Text = "视频下载进度:"; tsbBar.Value = 0; dgvResult.SelectedRows[0].Cells["VideoDownLoadState"].Value = "已下载"; } }
private bool DownLoadFile(string copyPath) { bool downResult = false; bool downMyJobResult = false; string downLoadUrl = string.Empty; string filePath = string.Empty; string fileName = string.Empty; string savePath = string.Empty; string ftpFilePath = "C:\\data\\"; string ftpServerIp = UserConfigSettings.Instance.ReadSetting("题库地址"); string ftpRemotePath = UserConfigSettings.Instance.ReadSetting("题库目录"); string ftpPort = UserConfigSettings.Instance.ReadSetting("端口号"); string ftpUserId = UserConfigSettings.Instance.ReadSetting("ftp用户名"); string ftpPassword = UserConfigSettings.Instance.ReadSetting("ftp密码"); bool anonymous = bool.Parse(UserConfigSettings.Instance.ReadSetting("匿名")); FtpWeb ftpWeb = new FtpWeb(ftpServerIp, ftpRemotePath, ftpUserId, ftpPassword, ftpPort, 10000, false, anonymous); M_Resource resource = dgvResult.SelectedRows[0].DataBoundItem as M_Resource; try { btnDownLoad.Enabled = false; //下载地址 downLoadUrl = fileHost.Replace(@"\", @"/") + resource.RSPath; //文件路径 filePath = resource.RSPath; //文件名 fileName = Path.GetFileName(filePath); //下载文件保存路径 savePath = string.Format("C:\\{0}_{1}", PublicClass.StudentCode, fileName); //下载作业 //downResult = CommonUtil.DownloadFile(downLoadUrl, savePath, tsbBar, tsbMessage, "下载进度:"); ftpWeb.Download(ftpFilePath, resource.RSPath, "", tsbBar, tsbMessage, "下载进度:"); if (downResult) { //解压资源到目录 ZipFileTools.UnZipSZL(savePath, copyPath); //删除下载文件 File.Delete(savePath); //设置已下载状态 dgvResult.SelectedRows[0].Cells["DownLoadState"].Value = "已下载"; downMyJobResult = true; } } catch (Exception ex) { PublicClass.ShowMessageOk(ex.Message); downMyJobResult = false; } finally { btnDownLoad.Enabled = true; } return(downMyJobResult); }
public string cdicom(string blh, DataTable bljc, sqldb aa, ref string dcmlb) { string ftplocal = @"c:\temp_sr\" + blh; try { System.IO.Directory.CreateDirectory(ftplocal); } catch { } IniFiles2 f = new IniFiles2(Application.StartupPath + "\\sz.ini"); string ftpserver = f.ReadString("ftp", "ftpip", "").Replace("\0", ""); string ftpuser = f.ReadString("ftp", "user", "ftpuser").Replace("\0", ""); string ftppwd = f.ReadString("ftp", "pwd", "ftp").Replace("\0", ""); //string ftplocal = f.ReadString("ftp", "ftplocal", "c:\\temp_sr").Replace("\0", ""); string ftpremotepath = f.ReadString("ftp", "ftpremotepath", "pathimages").Replace("\0", ""); FtpWeb fw = new FtpWeb(ftpserver, ftpremotepath, ftpuser, ftppwd); string txml = bljc.Rows[0]["F_txml"].ToString().Trim(); DataTable txlb = aa.GetDataTable("select top 4 * from V_DYTX where F_blh='" + blh + "' and (F_pacs IS NULL OR f_PACS<>'3')", "txlb"); for (int i = 0; i < txlb.Rows.Count; i++) { string ftpstatus = ""; fw.Download(ftplocal, txml + "/" + txlb.Rows[i]["F_txm"].ToString().Trim(), txlb.Rows[i]["F_txm"].ToString().Trim(), out ftpstatus); if (ftpstatus == "Error") { log.WriteMyLog("图像下载失败!"); return(""); } } //DataTable txb = aa.GetDataTable("select top 4 * from V_dytx where F_blh='" + blh + "'", "txb"); for (int i = 0; i < txlb.Rows.Count; i++) { string dcmname = @"c:\temp_sr\" + blh + @"\" + i.ToString() + ".dcm"; dicomfilezh df = new dicomfilezh(); df.createdicom(blh, aa, @"c:\temp_sr\" + blh + @"\" + txlb.Rows[i]["F_txm"].ToString().Trim(), ref dcmname, ""); if (dcmname == "") { log.WriteMyLog("重新生成一次!"); df.createdicom(blh, aa, @"c:\temp_sr\" + blh + @"\" + txlb.Rows[i]["F_txm"].ToString().Trim(), ref dcmname, ""); } if (dcmname != "") { aa.ExecuteSQL("update T_tx set F_pacs='" + dcmname + "' where F_id='" + txlb.Rows[i]["F_id"].ToString().Trim() + "'"); dcmlb = dcmlb + dcmname + "^"; } } return("true"); }
/// <summary> /// 删除订单目录 /// </summary> /// <param name="ftpServerIP">FTP 主机地址</param> /// <param name="folderToDelete">FTP 用户名</param> /// <param name="ftpUserID">FTP 用户名</param> /// <param name="ftpPassword">FTP 密码</param> public static void DeleteOrderDirectory(string ftpServerIP, string folderToDelete, string ftpUserID, string ftpPassword) { try { if (!string.IsNullOrEmpty(ftpServerIP) && !string.IsNullOrEmpty(folderToDelete) && !string.IsNullOrEmpty(ftpUserID) && !string.IsNullOrEmpty(ftpPassword)) { FtpWeb fw = new FtpWeb(ftpServerIP, folderToDelete, ftpUserID, ftpPassword); //进入订单目录 fw.GotoDirectory(folderToDelete, true); //获取规格目录 string[] folders = fw.GetDirectoryList(); foreach (string folder in folders) { if (!string.IsNullOrEmpty(folder) || folder != "") { //进入订单目录 string subFolder = folderToDelete + "/" + folder; fw.GotoDirectory(subFolder, true); //获取文件列表 string[] files = fw.GetFileList("*.*"); if (files != null) { //删除文件 foreach (string file in files) { fw.Delete(file); } } //删除冲印规格文件夹 fw.GotoDirectory(folderToDelete, true); fw.RemoveDirectory(folder); } } //删除订单文件夹 string parentFolder = folderToDelete.Remove(folderToDelete.LastIndexOf('/')); string orderFolder = folderToDelete.Substring(folderToDelete.LastIndexOf('/') + 1); fw.GotoDirectory(parentFolder, true); fw.RemoveDirectory(orderFolder); } else { throw new Exception("FTP 及路径不能为空!"); } } catch (Exception ex) { throw new Exception("删除订单时发生错误,错误信息为:" + ex.Message); } }
protected void LinkButton1_Click(object sender, EventArgs e) { string bb = "/huizhi/0531/容器及换热器/0531-D-2200-EQ-LS020-2001A$4376885.xls"; string ftpServerIP = "10.151.131.53"; string ftpRemotePath = ""; string ftpUserID = "CPMSPowerOn"; string ftpURI = "Cpms20150610"; FtpWeb Fw = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpURI); string filePath = "D:"; string fileName = bb.Substring(bb.LastIndexOf(@"/") + 1, bb.Length - bb.LastIndexOf(@"/") - 1); string ftpaddress = Fw.ftpURI + bb; Fw.Download(filePath, fileName, ftpaddress); }
protected void Page_Load(object sender, EventArgs e) { string bb = "/huizhi/1348/电气/1348-D-00670-EE-DW017-0002A$4376553.tif"; string ftpServerIP = "10.151.131.53"; string ftpRemotePath = ""; string ftpUserID = "CPMSPowerOn"; string ftpURI = "Cpms20150610"; FtpWeb Fw = new FtpWeb(ftpServerIP, ftpRemotePath, ftpUserID, ftpURI); string filePath = "D:\\"; string fileName = bb.Substring(bb.LastIndexOf(@"/") + 1, bb.Length - bb.LastIndexOf(@"/") - 1); string ftpaddress = Fw.ftpURI + bb.Substring(0, bb.LastIndexOf(@"/")); //Fw.Download(filePath, fileName, ftpaddress); //dd(); }
public static FtpWeb GetFtpWeb() { var checkResult = false; var pattern = false; var message = string.Empty; var ftpServerIp = UserConfigSettings.Instance.ReadSetting("题库地址"); var ftpRemotePath = UserConfigSettings.Instance.ReadSetting("题库目录"); var ftpPort = UserConfigSettings.Instance.ReadSetting("端口号"); var ftpUserId = UserConfigSettings.Instance.ReadSetting("ftp用户名"); var ftpPassword = UserConfigSettings.Instance.ReadSetting("ftp密码"); var anonymous = bool.Parse(UserConfigSettings.Instance.ReadSetting("匿名")); FtpWeb ftpWeb = null; checkResult = FtpWebTest.CheckFtp(ftpServerIp, ftpUserId, ftpPassword, ftpPort, pattern, anonymous, ftpRemotePath, out message); if (checkResult == true) { ftpWeb = new FtpWeb(ftpServerIp, ftpRemotePath, ftpUserId, ftpPassword, ftpPort, 10000, pattern, anonymous); } return(ftpWeb); }
private static bool Upload(string localDir, string remoteDir) { var ftp = new FtpWeb( DbFactory.FTPSetting.Server, DbFactory.FTPSetting.Port, DbFactory.FTPSetting.UserID, DbFactory.FTPSetting.Password); var sdir = remoteDir.ExtendSplit("/"); var changeDir = ""; for (int i = 0; i < sdir.Length; i++) { if (sdir[i] == "") { continue; } if (!ftp.DirectoryExist(changeDir, sdir[i])) { ftp.CreateDirectory(string.Format("{0}{1}/", changeDir, sdir[i])); } changeDir = string.Format("{0}{1}/", changeDir, sdir[i]); } var di = new DirectoryInfo(localDir); if (!di.Exists) { return(false); } foreach (FileInfo fi in di.GetFiles()) { if (!ftp.Upload(remoteDir + fi.Name, fi.FullName)) { return(false); } } return(true); }
public FtpHelper() { string ftpserver = f.ReadString("ftp", "ftpip", "").Replace("\0", ""); string ftpuser = f.ReadString("ftp", "user", "ftpuser").Replace("\0", ""); string ftppwd = f.ReadString("ftp", "pwd", "ftp").Replace("\0", ""); string ftplocal = f.ReadString("ftp", "ftplocal", "c:\\temp").Replace("\0", ""); string ftpremotepath = f.ReadString("ftp", "ftpremotepath", "pathimages").Replace("\0", ""); string ftps = f.ReadString("ftp", "ftp", "").Replace("\0", ""); string txpath = f.ReadString("txpath", "txpath", "").Replace("\0", ""); ftpPis = new FtpWeb(ftpserver, ftpremotepath, ftpuser, ftppwd); string ftpserver2 = f.ReadString("ftpup", "ftpip", "").Replace("\0", ""); string ftpuser2 = f.ReadString("ftpup", "user", "ftpuser").Replace("\0", ""); string ftppwd2 = f.ReadString("ftpup", "pwd", "ftp").Replace("\0", ""); string ftplocal2 = f.ReadString("ftpup", "ftplocal", "c:\\temp").Replace("\0", ""); string ftpremotepath2 = f.ReadString("ftpup", "ftpremotepath", "").Replace("\0", ""); string ftps2 = f.ReadString("ftp", "ftp", "").Replace("\0", ""); ftpUp = new FtpWeb(ftpserver2, ftpremotepath2, ftpuser2, ftppwd2); }
public bool psdicomfile(string blh) { bool dicom = true; IniFiles2 f = new IniFiles2(Application.StartupPath + "\\sz.ini"); string ftplocal = f.ReadString("Dicom", "local", @"c:\temp\").Replace("\0", "") + blh; try { dbbase.odbcdb aa = new odbcdb("DSN=pathnet;UID=pathnet;PWD=4s3c2a1p", "", ""); DataTable txlb = aa.GetDataTable("select top 4 * from V_dytx where F_blh='" + blh + "'", "dytx"); string ftpserver = f.ReadString("ftp", "ftpip", "").Replace("\0", ""); string ftpuser = f.ReadString("ftp", "user", "ftpuser").Replace("\0", ""); string ftppwd = f.ReadString("ftp", "pwd", "ftp").Replace("\0", ""); string ftpremotepath = f.ReadString("ftp", "ftpremotepath", "pathimages").Replace("\0", ""); FtpWeb fw = new FtpWeb(ftpserver, ftpremotepath, ftpuser, ftppwd); if (System.IO.Directory.Exists(ftplocal)) { } else { System.IO.Directory.CreateDirectory(ftplocal); } DataTable bljc = aa.GetDataTable("select * from T_jcxx where F_blh='" + blh + "'", "bljc"); string txml = bljc.Rows[0]["F_txml"].ToString().Trim(); int count = 0; log.WriteMyLog(blh + ",开始FTP图像下载"); for (int i = 0; i < txlb.Rows.Count; i++) { string ftpstatus = ""; fw.Download(ftplocal, txml + "/" + txlb.Rows[i]["F_txm"].ToString().Trim(), txlb.Rows[i]["F_txm"].ToString().Trim(), out ftpstatus); if (ftpstatus == "Error") { log.WriteMyLog(blh + ",图像下载失败!" + txlb.Rows[i]["F_txm"].ToString().Trim()); System.IO.Directory.Delete(ftplocal, true); return(false); } log.WriteMyLog(blh + ",图像下载成功" + txlb.Rows[i]["F_txm"].ToString().Trim()); string bmpmc = ftplocal + "\\" + txlb.Rows[i]["F_txm"].ToString().Trim(); string dcmmc = ftplocal + "\\" + txlb.Rows[i]["F_txm"].ToString().Trim().Replace(".", "") + ".dcm"; dicomfile xx = new dicomfile(); string errMsg = xx.createdicom(blh, aa, bmpmc, ref dcmmc); if (errMsg != "true") { log.WriteMyLog("[生成idcom文件失败]" + errMsg); } else { log.WriteMyLog("[生成idcom文件名]" + dcmmc); } if (dcmmc != "") { Process prc = new Process(); prc.StartInfo.FileName = @"cmd.exe"; prc.StartInfo.UseShellExecute = false; prc.StartInfo.RedirectStandardInput = true; prc.StartInfo.RedirectStandardOutput = true; prc.StartInfo.RedirectStandardError = true; prc.StartInfo.CreateNoWindow = true; prc.Start(); string server = f.ReadString("Dicom", "server", "194.1.13.169").Replace("\0", ""); string port = f.ReadString("Dicom", "port", "5500").Replace("\0", ""); string Aec = f.ReadString("Dicom", "Aec", "KC_IPEX_P001").Replace("\0", ""); string dos_cmd = @"storescu -aet LGPACS -aec " + Aec + " " + server + " " + port + " " + dcmmc; prc.StandardInput.WriteLine(dos_cmd); prc.StandardInput.Close(); string output = prc.StandardOutput.ReadToEnd(); //string output = prc.StandardOutput.ReadLine(); prc.WaitForExit(); string err = errcode(output); if (err != "") { log.WriteMyLog(txlb.Rows[i]["F_txm"].ToString().Trim() + ",发送失败" + err + " " + output); } else { log.WriteMyLog(txlb.Rows[i]["F_txm"].ToString().Trim() + ",发送成功 " + output); count = count + 1; } } else { log.WriteMyLog(blh + ",医院名称为空不处理"); return(false); } } // System.IO.Directory.Delete(ftplocal, true); if (count == txlb.Rows.Count) { return(true); } else { return(false); } } catch (Exception ee) { log.WriteMyLog(blh + ",程序异常:" + ee.Message); // System.IO.Directory.Delete(ftplocal, true); return(false); } }
private void Btn_UploadFile_Click(object sender, EventArgs e) { try { string FtpServer = ConfigInfo.FtpSite; string FtpUser = ConfigInfo.FtpUid; string FtpPassword = ConfigInfo.FtpPwd; FtpWeb ftp = new FtpWeb(FtpServer, ConfigInfo.FtpSiteDicPath.Trim('/'), FtpUser, FtpPassword); var FileList = lst_filelist.Items.Count; if (FileList == 0) { MessageBox.Show("请选择需要上传的工艺图纸!", "提示"); return; } if (string.IsNullOrEmpty(lblFigureNumber.Text)) { MessageBox.Show("图号为空!", "提示"); return; } new Thread(new ThreadStart(delegate { 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; string url = string.Format(@"http://{0}/api/Mms/MES_BN_ProductProcessRoute/GetUpdateProcessFigureIsEnableByProcessBomID?processBomID=" + parModel.BomID, ConfigInfo.API); 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", ConfigInfo.API); string result1 = Helpers.HttpHelper.PostJSON(url1, new { id = parModel.BomID, docName = file_name, fileName = num, filePath = ftp_url }); this.lst_filelist.Items.Remove(item); if (FtpWeb.file_jd == TotalBytes) { StorageInfo.hubProxy.Invoke("finishUpload", JsonConvert.SerializeObject(new { UserCode = parModel.UserCode, UploadType = 1, Result = true, Data = new { }, Msg = @"图纸已上传完成!" })); lblFigureNumber.Text = string.Empty; DialogResult = DialogResult.OK; } } })) { IsBackground = true }.Start(); } catch (Exception ex) { DialogResult = DialogResult.No; } }
/// <summary> /// HTTP下载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDownLoad_Click(object sender, EventArgs e) { if (dgvResult.SelectedRows.Count == 0) { return; } M_MyJob myJob = dgvResult.SelectedRows[0].DataBoundItem as M_MyJob; myJob.StudentCode = PublicClass.StudentCode; #region //作业限定时间&&当前时间小于作业发布开始时间 if (myJob.HWSubmitTimeType.ToLower() == "true" && //1:限时,0:不限时 Globals.ServerTime < DateTime.Parse(myJob.ExamStartDateTime)) { PublicClass.ShowMessageOk("还没有到作业时间,不允许下载作业。"); return; } #endregion #region //作业限定时间&&不允许补交作业&&当前时间大于作业提交截止时间 if (myJob.HWSubmitTimeType.ToLower() == "true" && //true:限时,false:不限时 myJob.IsPay.ToLower() == "false" && //true:允许补交作业,false:不允许补交作业 Globals.ServerTime > DateTime.Parse(myJob.ExamEndDateTime)) { PublicClass.ShowMessageOk("对不起,您已经过了交作业时间。\n请联系老师允许您补交作业!"); return; } #endregion try { btnDownLoad.Enabled = false; this.ParentForm.Enabled = false; if (Globals.DownType == "1") { FtpWeb ftpWeb = CommonUtil.GetFtpWeb(); if (ftpWeb != null) { FtpDownload(myJob); } else { HttpDownload(myJob); } } else { HttpDownload(myJob); } } catch (Exception ex) { PublicClass.ShowMessageOk("下载作业出错,错误详情请参考系统日志。"); LogHelper.WriteLog(typeof(frmHomeWork), ex); CommonUtil.WriteLog(ex); } finally { btnDownLoad.Enabled = true; this.ParentForm.Enabled = true; } }
/// <summary> /// 病理图片上传到外部系统ftp,并获取病理图片xml字符串 /// </summary> /// <param name="jcxx">检查信息表</param> /// <returns></returns> public string GetImageFile(T_JCXX jcxx) { var sqlWhere = $" F_BLH='{jcxx.F_BLH}' and F_SFDY='1' "; var txList = new T_TX_DAL().GetList(sqlWhere); string imageFileString = ""; #region ftp变量声明 IniFiles f = new IniFiles("sz.ini"); string ftpserver = f.ReadString("ftp", "ftpip", "").Replace("\0", ""); string ftpuser = f.ReadString("ftp", "user", "ftpuser").Replace("\0", ""); string ftppwd = f.ReadString("ftp", "pwd", "ftp").Replace("\0", ""); string ftplocal = f.ReadString("ftp", "ftplocal", "c:\\temp").Replace("\0", ""); string ftpremotepath = f.ReadString("ftp", "ftpremotepath", "pathimages").Replace("\0", ""); string ftps = f.ReadString("ftp", "ftp", "").Replace("\0", ""); string txpath = f.ReadString("txpath", "txpath", "").Replace("\0", ""); FtpWeb fw = new FtpWeb(ftpserver, ftpremotepath, ftpuser, ftppwd); string ftpserver2 = f.ReadString("ftpup", "ftpip", "").Replace("\0", ""); string ftpuser2 = f.ReadString("ftpup", "user", "ftpuser").Replace("\0", ""); string ftppwd2 = f.ReadString("ftpup", "pwd", "ftp").Replace("\0", ""); string ftplocal2 = f.ReadString("ftpup", "ftplocal", "c:\\temp").Replace("\0", ""); string ftpremotepath2 = f.ReadString("ftpup", "ftpremotepath", "").Replace("\0", ""); string ftps2 = f.ReadString("ftp", "ftp", "").Replace("\0", ""); FtpWeb fwup = new FtpWeb(ftpserver2, ftpremotepath2, ftpuser2, ftppwd2); string ftpPath = $@"ftp:\\{ftpserver}\"; //这里要替换为本地配置文件的ftp路径 string ftpPath2 = $@"ftp:\\{ftpserver2}\"; //这里要替换为本地配置文件的ftp路径 #endregion for (int i = 0; i < txList.Count; i++) { var upFilePath = jcxx.F_TXML + "\\"; var upFileName = upFilePath + txList[i].F_TXM.Trim(); //下载图片 string ftpstatus = ""; if (!Directory.Exists(ftplocal + "\\" + upFilePath)) { Directory.CreateDirectory(ftplocal + "\\" + upFilePath); } try { fw.Download(ftplocal + "\\" + upFilePath, upFileName, txList[i].F_TXM.Trim(), out ftpstatus); if (ftpstatus == "Error") { throw new Exception("Error"); } } catch (Exception e) { log.WriteMyLog("下载ftp图片失败,病理号:" + jcxx.F_BLH + "\r\n失败原因:" + e.Message); continue; } //上传到目标ftp string ftpstatusUP = ""; try { fwup.Makedir("BL", out ftpstatusUP); fwup.Makedir("BL\\" + upFilePath, out ftpstatusUP); fwup.Upload(ftplocal + "\\" + upFileName, "BL\\" + upFilePath, out ftpstatusUP); if (ftpstatusUP == "Error") { throw new Exception("Error"); } } catch (Exception e) { log.WriteMyLog("上传ftp图片失败,病理号:" + jcxx.F_BLH + "\r\n失败原因:" + e.Message); continue; } imageFileString += $@"<Path{i + 1}> {ftpPath2 + "BL\\" + upFileName} | 1 </Path{i + 1}> "; } return(imageFileString); }
/// <summary> /// 下载题库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDown_Click(object sender, EventArgs e) { #region 局部变量 string topicFileName = string.Empty; string topicFilePath = string.Empty; string topicEnvFilePath = string.Empty; string topicVideoFilePath = string.Empty; string requireEnvFile = string.Empty; string envFileName = string.Empty; string envFilePath = string.Empty; string videoFileName = string.Empty; string videoFilePath = string.Empty; string envFileExt = string.Empty; string copyEnvPath = string.Empty; string copyVideoPath = string.Empty; string filePath = string.Empty; string fileTPath = string.Empty; string fileExt = string.Empty; string fileName = string.Empty; string copyPath = string.Empty; string copyTPath = string.Empty; string connection = string.Empty; string connectionT = string.Empty; string errorMessage = string.Empty; FtpWeb ftpWeb = null; #endregion try { btnDown.Enabled = false; if (dgvDownTopicDB.SelectedRows.Count == 0) { return; } M_TopicDB topicDB = dgvDownTopicDB.SelectedRows[0].DataBoundItem as M_TopicDB; #region 检测本地是否存在题库文件 string path = string.Format(@"{0}\data\{1}_{2}.sdbt", Application.StartupPath, PublicClass.StudentCode, topicDB.TopicDBName); if (File.Exists(path)) { M_SubjectProp subject = bSubjectProp.GetSubjectProp(string.Format("{0}_{1}.sdbt", PublicClass.StudentCode, topicDB.TopicDBName)); if (subject.TopicDBVersion == topicDB.TopicDBVersion && subject.TopicDBCode == topicDB.TopicDBCode) { PublicClass.ShowErrorMessageOk("您已经下载过这个题库文件,不能重复下载。"); return; } } #endregion #region 初始化变量 topicFileName = Path.GetFileName(topicDB.TopicDBPath); topicFilePath = Path.GetDirectoryName(topicDB.TopicDBPath).Replace("\\", "//"); requireEnvFile = string.IsNullOrEmpty(topicDB.RequireEnvFile) == true ? "false" : topicDB.RequireEnvFile.ToLower(); filePath = string.Format("{0}\\{1}", Globals.DownLoadDir, topicFileName); fileTPath = string.Format("{0}\\{1}t", Globals.DownLoadDir, topicFileName); fileExt = string.IsNullOrEmpty(topicDB.TopicDBPath) == true ? "" : Path.GetExtension(topicDB.TopicDBPath).ToLower(); fileName = string.Format("{0}{1}", topicDB.TopicDBName, fileExt); copyPath = string.Format(@"{0}\data\{1}_{2}", Application.StartupPath, PublicClass.StudentCode, fileName.Replace(".srk", ".sdb")); copyTPath = string.Format(@"{0}\data\{1}_{2}t", Application.StartupPath, PublicClass.StudentCode, fileName.Replace(".srk", ".sdb")); connection = string.Format(@"data source={0};password={1};polling=false;failifmissing=true", filePath, PublicClass.PasswordTopicDB); connectionT = string.Format(@"data source={0};polling=false;failifmissing=true", fileTPath); #endregion //下载题库文件 ftpWeb = CommonUtil.GetFtpWeb(); if (ftpWeb != null) { ftpWeb.Download(Globals.DownLoadDir, topicFileName, topicFilePath, proDown, lblDown, "题库下载进度:"); } else { Msg.ShowInformation("FTP地址不可用,请返回登陆界面进行配置。"); return; } //下载账套文件 if (ftpWeb != null && requireEnvFile == "true" && topicDB.IsUploadEnvFile == true && !string.IsNullOrEmpty(topicDB.EnvFilePath)) { envFileName = Path.GetFileName(topicDB.EnvFilePath); envFilePath = string.Format("{0}\\{1}", Globals.DownLoadDir, envFileName); copyEnvPath = string.Format(@"{0}\SowerTestClient\Paper\Account\{1}", Application.StartupPath, envFileName); topicEnvFilePath = Path.GetDirectoryName(topicDB.EnvFilePath).Replace("\\", "//"); ftpWeb.Download(Globals.DownLoadDir, envFileName, topicEnvFilePath, proDown, lblDown, "账套下载进度:"); } //下载视频文件 if (ftpWeb != null && topicDB.IsUploadVideoFile == true && !string.IsNullOrEmpty(topicDB.VideoFilePath)) { videoFileName = Path.GetFileName(topicDB.VideoFilePath); videoFilePath = string.Format("{0}\\{1}", Globals.DownLoadDir, videoFileName); copyVideoPath = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}\", Application.StartupPath, PublicClass.StudentCode, DirFileHelper.GetFileNameNoExtension(videoFileName)); topicVideoFilePath = Path.GetDirectoryName(topicDB.VideoFilePath).Replace("\\", "//"); ftpWeb.Download(Globals.DownLoadDir, videoFileName, topicVideoFilePath, proDown, lblDown, "视频下载进度:"); } #region 验证题库文件 if (fileExt != ".sdb" && fileExt != ".srk") { Msg.ShowError("该文件不是有效的题库文件,请重新添加!"); return; } if (File.Exists(copyTPath) && File.Exists(copyPath)) { if (!Msg.AskQuestion("该题库文件已经存在,确定要覆盖吗?")) { return; } } if (File.Exists(filePath)) { CommonUtil.ShowProcessing("正在验证题库,请稍候...", this, (obj) => { //复制一个.sdbt文件 DirFileHelper.CopyFile(filePath, fileTPath); //修改.sdbt文件密码 bool updateResult = key3.ChangePassWordByGB2312(fileTPath, PublicClass.PassWordTopicDB_SDB, ""); if (updateResult) { SQLiteConnection conn = new SQLiteConnection(connectionT); conn.Open(); if (ConnectionState.Open == conn.State) { //更改题库密码 conn.ChangePassword(PublicClass.PasswordTopicDB); //复制题库到系统目录 DirFileHelper.CopyFile(filePath, copyPath); DirFileHelper.CopyFile(fileTPath, copyTPath); //复制账套到系统目录 if (requireEnvFile == "true" && topicDB.IsUploadEnvFile == true && !string.IsNullOrEmpty(topicDB.EnvFilePath)) { DirFileHelper.CopyFile(envFilePath, copyEnvPath); } //复制视频到系统目录 if (topicDB.IsUploadVideoFile == true && !string.IsNullOrEmpty(topicDB.VideoFilePath)) { ZipFileTools.UnZipSZL(videoFilePath, copyVideoPath); } conn.Close(); } conn.Dispose(); conn = null; DirFileHelper.DeleteFile(filePath); DirFileHelper.DeleteFile(fileTPath); DirFileHelper.DeleteFile(envFilePath); DirFileHelper.DeleteFile(videoFilePath); } else { Msg.ShowError("该题库不是有效的题库文件!"); } key3.Dispose(); }, null); } #endregion } catch (SQLiteException se) { Msg.ShowError("无法打开题库文件,该题库不是有效的题库文件!"); LogHelper.WriteLog(typeof(frmDownTopicDB), se); CommonUtil.WriteLog(se); } catch (WebException we) { Msg.ShowError("该题库文件不存在,请联系管理员重新上传。"); LogHelper.WriteLog(typeof(frmDownTopicDB), we); CommonUtil.WriteLog(we); } catch (AggregateException ae) { Msg.ShowError("无法打开题库文件,该题库不是有效的题库文件!"); LogHelper.WriteLog(typeof(frmDownTopicDB), ae); CommonUtil.WriteLog(ae); } catch (Exception ex) { PublicClass.ShowErrorMessageOk(ex.Message); LogHelper.WriteLog(typeof(frmDownTopicDB), ex); CommonUtil.WriteLog(ex); } finally { btnDown.Enabled = true; } }
private void Btn_UploadFile_Click(object sender, EventArgs e) { ILog log = LogManager.GetLogger("ErrorName"); try { string FtpServer = ConfigInfo.FtpSite; string FtpUser = ConfigInfo.FtpUid; string FtpPassword = ConfigInfo.FtpPwd; FtpWeb ftp = new FtpWeb(FtpServer, "PRS_ProcessFigure", FtpUser, FtpPassword); var FileList = lst_filelist.Items.Count; if (FileList == 0) { MessageBox.Show("请选择需要上传的工艺图纸!", "提示"); return; } if (lblFigureNumber.Text == "图号:") { MessageBox.Show("图号为空!", "提示"); return; } new Thread(new ThreadStart(delegate { 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, ConfigInfo.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", ConfigInfo.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); } } })) { IsBackground = true }.Start(); } catch (Exception ex) { log.Error(ex.Message); } }