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 void HttpDownload(M_MyJob myJob) { //下载地址 string downLoadUrl = string.Format("{0}/{1}", fileHost, myJob.FilePath.Replace(@"\", @"/")); //文件路径 string filePath = myJob.FilePath; //文件名 string fileName = Path.GetFileName(filePath); //复制文件到系统路径 string copyPath = string.Format(@"{0}\SowerTestClient\Paper\Download\{1}_{2}", Application.StartupPath, PublicClass.StudentCode, fileName); //下载文件保存路径 string savePath = string.Format("{0}\\{1}_{2}", Globals.DownLoadDir, PublicClass.StudentCode, fileName); //下载作业 bool downResult = CommonUtil.DownloadFile(downLoadUrl, savePath, tsbBar, tsbMessage, "作业下载进度:"); if (downResult) { //复制作业到系统目录 File.Copy(savePath, copyPath, true); //删除下载文件 File.Delete(savePath); //设置已下载状态 dgvResult.SelectedRows[0].Cells["JobDownLoadState"].Value = "已下载"; tsbMessage.Text = "作业下载进度:"; tsbBar.Value = 0; } if (myJob.RequireEnvFile.ToLower() == "true" && myJob.IsUpload.ToLower() == "true" && cbIsDownAccount.Checked == true) { downLoadUrl = string.Format("{0}/{1}", fileHost, myJob.EnvFilePath.Replace(@"\", @"/")); filePath = myJob.FilePath; fileName = myJob.EnvFileName; copyPath = string.Format(@"{0}\SowerTestClient\Paper\Account\{1}", Application.StartupPath, fileName); savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName); downResult = CommonUtil.DownloadFile(downLoadUrl, savePath, tsbBar, tsbMessage, "帐套下载进度:"); if (downResult) { //复制作业到系统目录 DirFileHelper.Copy(savePath, copyPath); //删除临时下载文件 DirFileHelper.DeleteFile(savePath); tsbMessage.Text = "账套下载进度:"; tsbBar.Value = 0; dgvResult.SelectedRows[0].Cells["AccountDownLoadState"].Value = "已下载"; } } //下载视频文件 if (string.IsNullOrEmpty(myJob.VideoFilePath) == false && myJob.IsUploadVideoFile == true && cbIsDownVideo.Checked == true) { downLoadUrl = string.Format("{0}/{1}", fileHost, myJob.VideoFilePath.Replace(@"\", @"/")); filePath = myJob.VideoFilePath; fileName = myJob.VideoFileName; copyPath = string.Format(@"{0}\SowerTestClient\Video\{1}_{2}", Application.StartupPath, PublicClass.StudentCode, Path.GetFileNameWithoutExtension(fileName)); savePath = string.Format("{0}\\{1}", Globals.DownLoadDir, fileName); downResult = CommonUtil.DownloadFile(downLoadUrl, savePath, tsbBar, tsbMessage, "视频下载进度:"); if (downResult) { //复制作业到系统目录 ZipFileTools.UnZipSZL(savePath, copyPath); //删除临时下载文件 DirFileHelper.DeleteFile(savePath); tsbMessage.Text = "视频下载进度:"; tsbBar.Value = 0; dgvResult.SelectedRows[0].Cells["VideoDownLoadState"].Value = "已下载"; } } }