Exemplo n.º 1
0
 /// <summary>
 /// 将没在记录之中的文件从FTP上下载
 /// </summary>
 public void FtpToLocal()
 {
     for (int i = 0; i < listNotRecord.typeList.Count; i++)
     {
         for (int j = 0; j < listNotRecord.typeList[i].files.Count; j++)
         {
             fh.GotoDirectory(cConfig.strFtpRoot + "/" + listNotRecord.typeList[i].name, true);
             fh.Download(cConfig.strWorkPath + "\\" + listNotRecord.typeList[i].name, listNotRecord.typeList[i].files[j].name);
             cAccess.add(listNotRecord.typeList[i].files[j].name, "",
                         cConfig.strWorkPath + "\\" + listNotRecord.typeList[i].name + "\\" + listNotRecord.typeList[i].files[j].name,
                         listNotRecord.typeList[i].name, "", cConfig.FTP_IP, "从FTP上下载的文件");
         }
     }
 }
        /// <summary>
        /// 下载所选文件
        /// </summary>
        /// <param name="sender">传递对象</param>
        /// <param name="e">传递事件</param>
        private void btnDownloadFile_Click(object sender, EventArgs e)
        {
            if (null == _ftpHelper)
            {
                MessageBox.Show("请先创建FTP服务!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            lblStatusInfo.Text = "等待...";

            string saveFullPath = txtFileOrName.Text.Trim();

            if (string.IsNullOrEmpty(saveFullPath))
            {
                MessageBox.Show("对不起!请先选择好下载文件的保存位置,然后重试。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtFileOrName.Focus();
                return;
            }

            string selectedFile = lstDataBox.SelectedItem as string;

            if (string.IsNullOrWhiteSpace(selectedFile))
            {
                MessageBox.Show("您暂未选中任何文件,或列表中没有文件可供选择,请先执行获取基本列表,并确认选中了文件后重试。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string resultString = _ftpHelper.Download(saveFullPath, selectedFile);

            lblStatusInfo.Text = $"{_ftpHelper.CurrentStatusCode} : {resultString}";
        }
Exemplo n.º 3
0
        /// <summary>
        /// 下载文件
        /// </summary>
        private void OnDowloadFile()
        {
            var            temp    = fTPF002FileBindingSource.Current as FTP_F002_File;
            SaveFileDialog saveDig = new SaveFileDialog();

            saveDig.Filter   = "(*" + temp.Extension + ")" + "|*" + temp.Extension;//"*"+temp.Extension;//文本文件(*.txt)|*.txt
            saveDig.FileName = temp.ServiceName;
            if (saveDig.ShowDialog() == DialogResult.OK)
            {
                ftpHepler.Download(saveDig.FileName, temp.ServiceName);
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //var record_id = Request.Params["fileid"];
            //if (string.IsNullOrEmpty(record_id))
            //{
            //    Response.Write("参数缺失或不正确...");
            //    Response.End();
            //}


            //FtpFileService file_service = new FtpFileService();
            //var file = file_service.GenericService.GetModel(record_id);
            //if (file == null) {

            //    Response.Write("参数缺失或不正确...");
            //    Response.End();
            //}
            //var ftp_file_name = file.FileName;
            //var ftp_path = file.Path;

            var ftp_file_name = "down_load_attach.jpg";
            var ftp_path      = "/部门111111/20190624_zhanxl.jpg";

            var ftp_helper = new FTPHelper("172.16.7.114", "dzafc\\zhanxl", "!!1234abcd", 7000);

            ftp_helper.Download("", "", "");
            //Stream fs = ftp_helper.GetDownloadFileStream(ftp_path);
            //byte[] bytes = new byte[4096];
            //fs.Read(bytes, 0, bytes.Length);
            //fs.Seek(0, SeekOrigin.Begin);
            //fs.Close();

            //Response.ContentType = "application/octet-stream";
            //Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(ftp_file_name, System.Text.Encoding.UTF8));
            //Response.BinaryWrite(bytes);
            //Response.Flush();
            //Response.End();


            //ClientScript.RegisterStartupScript(
            //    Page.GetType(),
            //    "",
            //    "<script language=javascript>window.opener = null;window.open('','_self');window.close();</script>"
            //    );
        }
Exemplo n.º 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            #region 检查是否存在UpdateInfo.xml文件,如果不存在则启动设置窗口,创建UpdateInfo.xml文件,并配置该文件
            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory.ToString() + "UpdateInfo.xml"))
            {
                //启动设置窗口
                SettingsForm settingForm = new SettingsForm();
                settingForm.ShowDialog();
            }

            #endregion
            #region 连接到FTP,下载最新的XML配置文件到临时文件夹
            //从原程序目录下读取XML文件中的FTP信息,并下载最新的XML文件
            FTPPath     = XMLProcess.Read("UpdateInfo.xml", "UpdateInformation", "FTPInformation", "FTPPath");
            FTPUser     = XMLProcess.Read("UpdateInfo.xml", "UpdateInformation", "FTPInformation", "FTPUser");
            FTPPassword = XMLProcess.Read("UpdateInfo.xml", "UpdateInformation", "FTPInformation", "FTPPassword");
            //检查temp文件夹是否存在,并创建temp文件夹
            DirFile.CreateDir("temp");
            //将最新的XML文件下载到temp文件夹中
            ftp = new FTPHelper(FTPPath, "", FTPUser, FTPPassword);
            ftp.Download(FTPPath, AppDomain.CurrentDomain.BaseDirectory.ToString() + @"\temp", "UpdateInfo.xml");
            #endregion

            #region 获取临时文件夹XML文件中的版本更新日期,以及原程序的版本更新日期
            //获取旧版本版本号及更新时间
            strOldAppName       = XMLProcess.Read("UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationName");
            strOldAppVersion    = XMLProcess.Read("UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationVersion");
            strOldAppUpdateTime = XMLProcess.Read("UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationUpdateTime");
            strOldAppMessages   = XMLProcess.Read("UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationMessages");
            //获取新版本版本号及更新时间
            strNewAppName       = XMLProcess.Read(@"temp\UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationName");
            strNewAppVersion    = XMLProcess.Read(@"temp\UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationVersion");
            strNewAppUpdateTime = XMLProcess.Read(@"temp\UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationUpdateTime");
            strNewAppMessages   = XMLProcess.Read(@"temp\UpdateInfo.xml", "UpdateInformation", "ApplicationInformation", "ApplicationMessages");
            #endregion

            #region 比较两个版本的更新日期,提示用户是否升级,若选择不升级,则退出升级程序
            if (strOldAppVersion != strNewAppVersion || strOldAppUpdateTime != strNewAppUpdateTime)
            {
                VersionForm versionform = new VersionForm();
                versionform.ShowDialog();
            }
            else
            {
                Application.Exit();
            }
            #endregion

            #region 检测原程序是否在运行,若运行则杀死
            //检测原程序是否在运行,若运行则杀死。
            proc = Process.GetProcessesByName(strOldAppName);
            if (proc.Length != 0)
            {
                KillForm killform = new KillForm();
                killform.ShowDialog();
            }
            #endregion

            #region 开始批量下载文件到临时文件夹
            //下载FTP上的文件到temp文件夹
            string[] filelist = ftp.GetFileList(FTPPath);
            for (int i = 0; i < filelist.Length; i++)
            {
                ftp.Download(FTPPath, AppDomain.CurrentDomain.BaseDirectory.ToString() + @"\temp", filelist[i]);
            }
            //下载FTP上的文件夹到temp文件夹(包括文件夹下内容),如果没有文件夹,则folderlist.Length=0,不执行下列循环
            string[] folderlist = ftp.GetFolderList(FTPPath);
            for (int i = 0; i < folderlist.Length; i++)
            {
                //根据得到的文件夹列表,在temp下创建相应的文件夹
                DirFile.CreateDir(@"\temp\" + folderlist[i]);
                //获取该文件夹下的文件列表,并下载到文件夹下
                string   ftpURI        = FTPPath + folderlist[i] + "/";
                string[] InnerFilelist = ftp.GetFileList(ftpURI);
                for (int j = 0; j < InnerFilelist.Length; j++)
                {
                    ftp.Download(ftpURI, AppDomain.CurrentDomain.BaseDirectory.ToString() + @"\temp\" + folderlist[i], InnerFilelist[j]);
                }
            }
            #endregion

            #region 将原程序删除(包括文件和文件夹),拷贝临时文件夹中的文件到原目录
            //删除原程序中的文件
            string[] deletefilelist = DirFile.GetFileNames(AppDomain.CurrentDomain.BaseDirectory.ToString());
            for (int i = 0; i < deletefilelist.Length; i++)
            {
                if (!deletefilelist[i].Contains("UpdateProgram") & !deletefilelist[i].Contains("CSkin"))
                {
                    DirFile.DeleteFile(deletefilelist[i]);
                }
            }
            //删除原程序中的文件夹
            string[] deletefolderlist = DirFile.GetFolderNames(AppDomain.CurrentDomain.BaseDirectory.ToString());
            for (int i = 0; i < deletefolderlist.Length; i++)
            {
                if (!deletefolderlist[i].Contains("temp") & !deletefolderlist[i].Contains("Backup"))
                {
                    DirFile.DeleteDirectory(deletefolderlist[i]);
                }
            }
            //拷贝temp文件夹下文件到原程序目录
            string[] copyfilelist = DirFile.GetFileNames(AppDomain.CurrentDomain.BaseDirectory.ToString() + "temp");
            string[] strFileName  = new string[copyfilelist.Length];
            for (int i = 0; i < copyfilelist.Length; i++)
            {
                strFileName[i] = Path.GetFileName(copyfilelist[i]);
                DirFile.CopyFile(copyfilelist[i], AppDomain.CurrentDomain.BaseDirectory.ToString() + strFileName[i]);
            }
            //拷贝temp文件夹下文件夹到原程序目录
            string[] copyfolderlist = DirFile.GetFolderNames(AppDomain.CurrentDomain.BaseDirectory.ToString() + "temp");
            string[] strFolderName  = new string[copyfolderlist.Length];
            for (int i = 0; i < copyfolderlist.Length; i++)
            {
                strFolderName[i] = Path.GetFileName(copyfolderlist[i]);
                DirFile.CopyFolder(copyfolderlist[i], AppDomain.CurrentDomain.BaseDirectory.ToString() + strFolderName[i]);
            }
            #endregion

            #region 拷贝完成后,删除temp文件夹,提示更新完毕,然后启动新的主程序
            DirFile.DeleteDirectory(AppDomain.CurrentDomain.BaseDirectory.ToString() + "temp");
            Process.Start(strNewAppName + ".exe");
            #endregion

            Application.Run(new UpdateForm());
        }
Exemplo n.º 6
0
        /// <summary>
        /// 从来源获取公文
        /// </summary>
        /// <param name="Title">标题</param>
        /// <param name="Url">来源</param>
        /// <param name="type">公文类型</param>
        /// <param name="rlDate"></param>
        /// <param name="provider"></param>
        /// <param name="notes"></param>
        /// <param name="isAddRecord">是否记录进数据库</param>
        public static bool GetDoc(string Title, string Url, string type = "", string rlDate = "",
            string provider = "", string notes = "", bool isAddRecord = true)
        {
            try
            {
                Uri u = new Uri(Url);
                if (u.Scheme.ToLower() == "http")
                {//网址
                    List<cWord> lw = new List<cWord>();
                    lw.Add(new cWord(Title, u.AbsoluteUri, type, rlDate, provider, notes, isAddRecord));
                    cMakeWord mw = new cMakeWord(lw);
                    Thread th = new Thread(new System.Threading.ThreadStart(mw.makeWord));
                    th.Start();
                }
                else if (u.Scheme.ToLower() == "ftp")
                {
                    string ap = u.AbsolutePath.Substring(0, u.AbsolutePath.LastIndexOf('/'));
                    string file = u.AbsolutePath.Replace(ap, "");
                    //暂时不提供ftp文件的下载
                    FTPHelper _fh = new FTPHelper(u.Authority, ap, "", "");

                    _fh.Download(cConfig.strWorkPath + "\\" + type, file);
                    if (isAddRecord)
                        cAccess.add(Title, u.AbsoluteUri, cConfig.strWorkPath + "\\" + type + "\\" + file, type, rlDate, provider, notes);
                }
                else if (u.Scheme.ToLower() == "file")
                {//本地文件
                    string HouZui = u.LocalPath.Substring(u.LocalPath.LastIndexOf('.'));

                    string pFilePath;
                    if (type == "")
                        type = cConfig.strNoType;
                    pFilePath = cConfig.strWorkPath + "\\" + type;

                    if (!(Directory.Exists(pFilePath)))
                        Directory.CreateDirectory(pFilePath);

                    pFilePath += "\\" + Title + HouZui;
                    if (File.Exists(pFilePath))
                    {
                        //MessageBox.Show("公文库中已有同名公文,请修改公文标题或类型!");
                        return true;
                    }
                    File.Copy(Url, pFilePath);
                    if (isAddRecord)
                        cAccess.add(Title, u.LocalPath, pFilePath, type, rlDate, provider, notes);
                }
                else { return false; }
                frmMain.fm.initialize();
                return true;
            }
            catch
            {
                return false;
                throw;
            }
        }
Exemplo n.º 7
0
        ///// <summary>
        ///// 将FTP上被标记的文件下载下来
        ///// </summary>
        //public void record()
        //{
        //    for (int i = 0; i < FtpFS.typeList.Count; i++)
        //    {
        //        for (int j = 0; j < FtpFS.typeList[i].FileList.Count; j++)
        //        {
        //            if (!FtpFS.typeList[i].FileList[j].isRecord)
        //            {
        //                if (File.Exists(cConfig.strWorkPath + FtpFS.typeList[i].name + FtpFS.typeList[i].FileList[j].name))
        //                    continue;
        //                fh.Download(cConfig.strWorkPath + "\\" + FtpFS.typeList[i].name, FtpFS.typeList[i].FileList[j].name);

        //                cAccess.add(FtpFS.typeList[i].FileList[j].name, "",
        //                    cConfig.strWorkPath + FtpFS.typeList[i].name + FtpFS.typeList[i].FileList[j].name,
        //                    FtpFS.typeList[i].name, "", cConfig.FTP_IP, "从FTP上下载的文件");

        //                FtpFS.typeList[i].FileList[j].isRecord = true;
        //            }
        //        }
        //    }
        //}

        #region 静态方法

        /// <summary>
        /// 从来源获取公文
        /// </summary>
        /// <param name="Title">标题</param>
        /// <param name="Url">来源</param>
        /// <param name="type">公文类型</param>
        /// <param name="rlDate"></param>
        /// <param name="provider"></param>
        /// <param name="notes"></param>
        /// <param name="isAddRecord">是否记录进数据库</param>
        public static bool GetDoc(string Title, string Url, string type = "", string rlDate = "",
                                  string provider = "", string notes = "", bool isAddRecord = true)
        {
            try
            {
                Uri u = new Uri(Url);
                if (u.Scheme.ToLower() == "http")
                {//网址
                    List <cWord> lw = new List <cWord>();
                    lw.Add(new cWord(Title, u.AbsoluteUri, type, rlDate, provider, notes, isAddRecord));
                    cMakeWord mw = new cMakeWord(lw);
                    Thread    th = new Thread(new System.Threading.ThreadStart(mw.makeWord));
                    th.Start();
                }
                else if (u.Scheme.ToLower() == "ftp")
                {
                    string ap   = u.AbsolutePath.Substring(0, u.AbsolutePath.LastIndexOf('/'));
                    string file = u.AbsolutePath.Replace(ap, "");
                    //暂时不提供ftp文件的下载
                    FTPHelper _fh = new FTPHelper(u.Authority, ap, "", "");

                    _fh.Download(cConfig.strWorkPath + "\\" + type, file);
                    if (isAddRecord)
                    {
                        cAccess.add(Title, u.AbsoluteUri, cConfig.strWorkPath + "\\" + type + "\\" + file, type, rlDate, provider, notes);
                    }
                }
                else if (u.Scheme.ToLower() == "file")
                {//本地文件
                    string HouZui = u.LocalPath.Substring(u.LocalPath.LastIndexOf('.'));

                    string pFilePath;
                    if (type == "")
                    {
                        type = cConfig.strNoType;
                    }
                    pFilePath = cConfig.strWorkPath + "\\" + type;

                    if (!(Directory.Exists(pFilePath)))
                    {
                        Directory.CreateDirectory(pFilePath);
                    }

                    pFilePath += "\\" + Title + HouZui;
                    if (File.Exists(pFilePath))
                    {
                        //MessageBox.Show("公文库中已有同名公文,请修改公文标题或类型!");
                        return(true);
                    }
                    File.Copy(Url, pFilePath);
                    if (isAddRecord)
                    {
                        cAccess.add(Title, u.LocalPath, pFilePath, type, rlDate, provider, notes);
                    }
                }
                else
                {
                    return(false);
                }
                frmMain.fm.initialize();
                return(true);
            }
            catch
            {
                return(false);

                throw;
            }
        }