• 利用webclient ftpclient上传下载文件


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
     
    namespace OperateExcel
    {
        public partial class WebClient上传下载文件 : Form
        {
            public WebClient上传下载文件()
            {
                InitializeComponent();
            }
     
            //WebClient下载
            private void btnDownload_Click(object sender, EventArgs e)
            {
                WebClient wc = new WebClient();
                wc.Credentials = new NetworkCredential("wt""wangtao_20110902001@");
                wc.DownloadFile("ftp://192.168.0.231:15287/test.html"@"d:wt.html");
                MessageBox.Show("下载成功!");
            }
     
            //WebClient上传
            private void btnUpload_Click(object sender, EventArgs e)
            {
                WebClient wc = new WebClient();
                wc.Credentials = new NetworkCredential("wt""wangtao_20110902001@");
                wc.UploadFile("ftp://192.168.0.231:15287/test998.asp"@"d:SingleProduct_list.asp");
                MessageBox.Show("上传成功!");
            }
     
     
            //Ftp下载
            private void btnFtpDownload_Click(object sender, EventArgs e)
            {
                FtpClient fc = new FtpClient("192.168.0.231:15287""wt""wangtao_20110902001@");
                fc.Port = 15287;
                fc.RemotePath = "/new_admin/LessonSet/";
                
                bool flag = fc.Download("Teacher.asp"@"d:Teacher.asp");
     
                if (flag)
                {
                    MessageBox.Show("下载成功!");
                }
                else
                {
                    MessageBox.Show("下载失败");
                }
            }
     
            //Ftp上传
            private void btnFtpUpload_Click(object sender, EventArgs e)
            {
                FtpClient fc = new FtpClient("192.168.0.231:15287""wt""wangtao_20110902001@");
                fc.RemotePath="/new_admin/LessonSet/";
                fc.MakeDirectory("在当前路径下创建文件夹");
                FileInfo fInfo=new FileInfo(@"d:Teacher.asp");
                bool flag = fc.Upload(fInfo, "在当前路径下创建文件夹/test998.asp");
     
                if (flag)
                {
                    MessageBox.Show("上传成功!");
                }
                else
                {
                    MessageBox.Show("上传失败");
                }
            }
     
            //利用ftp上传Excel文件
            private void btnUploadExcel_Click(object sender, EventArgs e)
            {
                FtpClient fc = new FtpClient("192.168.0.231:15287""wt""wangtao_20110902001@");
                fc.RemotePath = "/new_admin/lessonset/";
                FileInfo fInfo = new FileInfo(this.label1.Text);
                bool flag=fc.Upload(fInfo,DateTime.Now.ToString()+".xls");
     
                if (flag)
                {
                    MessageBox.Show("上传成功!");
                }
                else
                {
                    MessageBox.Show("上传失败!");
                }
            }
     
            private void btnSelect_Click(object sender, EventArgs e)
            {
                openFileDialog1.Filter = "Excel|*.xls";
                openFileDialog1.Multiselect = false;
                DialogResult result = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    label1.Text = openFileDialog1.FileName;
                }
            }
        }
    }
  • 相关阅读:
    【LeetCode-回溯】组合总和
    MongoDB复制集成员类型
    Vant中的日期元素在iOS上显示NaN
    Vue风格
    Git设置代理和取消代理的方式
    吴晓波——疫情下的的“危”与“机”
    Vant库在PC端的使用
    买保险,不上当
    Vant的引入方式
    Duplicate keys detected: 'xxx'. This may cause an update error.
  • 原文地址:https://www.cnblogs.com/jiayue360/p/3166968.html
Copyright © 2020-2023  润新知