private void FtpTrans(SysBackupServerEntity model, string backupPath, string virtualPath, string strPath, string chkDrop)
        {
            Task.Run(() =>
            {
                if (model != null)
                {
                    FTPHelper ftp = new FTPHelper(model.F_FtpServerIp, "", model.F_FtpUserId, model.F_FtpPassword);
                    if (!ftp.IsDirectoryExist(backupPath))
                    {
                        ftp.CreateDirectory(backupPath);
                    }
                    ftp = new FTPHelper(model.F_FtpServerIp, backupPath, model.F_FtpUserId, model.F_FtpPassword);

                    ZipFloClass Zc = new ZipFloClass();               //将文件夹进行GZip压缩
                    Zc.ZipFile(Server.MapPath(virtualPath), strPath); //生成压缩包

                    if (chkDrop == "true")
                    {
                        //遍历删除当前目录文件
                        List <FileStruct> ListFiles = ftp.ListFiles();
                        if (ListFiles.Count > 0)
                        {
                            foreach (var item in ListFiles)
                            {
                                ftp.DeleteFile(item.Name);
                            }
                        }
                    }
                    ftp.Upload(strPath);            //通过ftp传到服务器
                    FileHelper.DeleteFile(strPath); //删除临时压缩包
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建目录
        /// </summary>
        /// <param name="sender">传递对象</param>
        /// <param name="e">传递事件</param>
        private void btnCreateDir_Click(object sender, EventArgs e)
        {
            if (null == _ftpHelper)
            {
                MessageBox.Show("请先创建FTP服务!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

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

            string dirName = txtFileOrName.Text.Trim();

            if (string.IsNullOrEmpty(dirName))
            {
                MessageBox.Show("您欲创建的目录名称不正确,请输入仅限目录名称的内容。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtFileOrName.Focus();
                return;
            }

            string resultString = _ftpHelper.CreateDirectory(dirName);

            lblStatusInfo.Text = $"{_ftpHelper.CurrentStatusCode} : {resultString}";
        }