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;
}
}
}
}