zoukankan      html  css  js  c++  java
  • 利用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;
                }
            }
        }
    }
  • 相关阅读:
    关于托管存储过程的部署, 调试和性能
    Fast Fourier Transform in C# (CookyTurkey)
    The Story of Lena(.tiff)
    反射之反思(转)
    分享Oracle9i中建立自增字段的最新办法
    C#操作注册表
    Oracle服务器的常用命令行详细讲解
    为汶川受灾群众祈福!!!!!
    新的开始,新的起点
    完全删除Oracle数据库的方法
  • 原文地址:https://www.cnblogs.com/jiayue360/p/3166968.html
Copyright © 2011-2022 走看看