VeviFTPHelper应用实例

 VeviFTP.VeviFtpHelper ftp;
        /// <summary>
        /// 连接FTP
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (ftp != null)
                ftp.Dispose();
            ftp = new VeviFTP.VeviFtpHelper(textBox1.Text,textBox6.Text, textBox2.Text, textBox3.Text);
            ftp.ShowErrorEvent += new VeviFTP.ShowError(ftp_ShowErrorEvent);
            if (ftp.PrepareFTPInfo())
            {
                if (ftp.ExitFTP())
                {
                    richTextBox1.AppendText("连接成功!" + "\r\n");
                }
            }
        }

        void ftp_ShowErrorEvent(string content, string title)
        {
            richTextBox1.AppendText(content + "      " + title + "\r\n");
        }

        private string PreparePath()
        {
            if (ftp == null)
                return "";
            return ftp.FTPRootURI + textBox4.Text;
        }
        /// <summary>
        /// 文件列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            string path = PreparePath();
            string info;
            IList<string> fileList = ftp.GetFileList(path,out info);
            if (info == "1")
            {
                foreach (string str in fileList)
                    richTextBox1.AppendText(str+"\r\n");
            }
        }
        /// <summary>
        /// 文件夹列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            string path = PreparePath();
            string info;
            IList<string> fileList = ftp.GetFolderList(path, out info);
            if (info == "1")
            {
                foreach (string str in fileList)
                    richTextBox1.AppendText(str + "\r\n");
            }
        }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog opdiag = new OpenFileDialog();
            opdiag.Filter = "所有文件(*.*)|*.*";
            //
            string path = PreparePath();
            if (opdiag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if(ftp.UploadFile(path, opdiag.FileName))
                    richTextBox1.AppendText("上传文件成功!" + "\r\n");
            }
        }
        /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            string path = PreparePath();
            if ( ftp.CreateFolder(path))
            {
                richTextBox1.AppendText("创建文件夹成功!" + "\r\n");
            }
        }
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button7_Click(object sender, EventArgs e)
        {
            string path = PreparePath();
            if (ftp.DeleteFile(path))
            {
                richTextBox1.AppendText("删除文件成功!" + "\r\n");
            }
        }
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fdiag = new FolderBrowserDialog();
            string path = PreparePath();
            if (fdiag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (ftp.DownLoadFile(path,fdiag.SelectedPath))
                {
                    richTextBox1.AppendText("下载文件成功!" + "\r\n");
                }
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            string path = PreparePath();
            if (ftp.DeleteFolder(path))
            {
                richTextBox1.AppendText("删除文件夹成功!" + "\r\n");
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            string path = PreparePath();
            string newName = textBox5.Text;
            if (ftp.ReName(path, newName))
            {
                richTextBox1.AppendText("重命名成功!" + "\r\n");
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值