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;
                }
            }
        }
    }
  • 相关阅读:
    SubtextHTTP 模块
    asp.net控件设计时支持(2)自动格式设置
    新立得字体模糊解决经验
    详解新网银木马清除技巧
    Ubuntu 9.10 29日发布,更新列表已经公布
    小样儿想封我?WebOS 1.2.1再次突破iTunes同步限制
    检测到您尚未安装ALEXA工具条
    在Puppy Linux中安装Firefox
    一步一步教你用ES封装系统(最完整视频教程)
    C# 判断是否为数字
  • 原文地址:https://www.cnblogs.com/jiayue360/p/3166968.html
Copyright © 2011-2022 走看看