C#实现FTP上传下载程序
2020-12-17 12:33
标签:tostring hub write ssl close event cep collect offset 本文是利用C# 实现FTP上传下载的小例子,以供学习分享使用。 涉及知识点: FtpWebRequest【实现文件传输协议 (FTP) 客户端】 / FtpWebResponse【封装文件传输协议 (FTP) 服务器对请求的响应】Ftp的操作。 效果图如下
核心代码如下 -------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------- 源码见github C#实现FTP上传下载程序 标签:tostring hub write ssl close event cep collect offset 原文地址:https://www.cnblogs.com/DWVictor/p/14036305.htmlusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Threading;
namespace 上传下载程序
{
public partial class Form1 : Form
{
private static readonly string rootPath = "/";
private static readonly int defaultReadWriteTimeout = 300000;
private static readonly int defaultFtpPort = 21;
#region 设置初始化参数
private string host = string.Empty;
public string Host
{
get
{
return this.host ?? string.Empty;
}
}
private string username = string.Empty;
public string Username
{
get
{
return this.username;
}
}
private string password = string.Empty;
public string Password
{
get
{
return this.password;
}
}
IWebProxy proxy = null;
public IWebProxy Proxy
{
get
{
return this.proxy;
}
set
{
this.proxy = value;
}
}
private int port = defaultFtpPort;
public int Port
{
get
{
return port;
}
set
{
this.port = value;
}
}
private bool enableSsl = false;
public bool EnableSsl
{
get
{
return enableSsl;
}
}
private bool usePassive = true;
public bool UsePassive
{
get
{
return usePassive;
}
set
{
this.usePassive = value;
}
}
private bool useBinary = true;
public bool UserBinary
{
get
{
return useBinary;
}
set
{
this.useBinary = value;
}
}
private string remotePath = rootPath;
public string RemotePath
{
get
{
return remotePath;
}
set
{
string result = rootPath;
if (!string.IsNullOrEmpty(value) && value != rootPath)
{
result = Path.Combine(Path.Combine(rootPath, value.TrimStart(‘/‘).TrimEnd(‘/‘)), "/"); // 进行路径的拼接
}
this.remotePath = result;
}
}
private int readWriteTimeout = defaultReadWriteTimeout;
public int ReadWriteTimeout
{
get
{
return readWriteTimeout;
}
set
{
this.readWriteTimeout = value;
}
}
#endregion
#region 构造函数
// public FtpHelper(string host, string username, string password)
// : this(host, username, password, defaultFtpPort, null, false, true, true, defaultReadWriteTimeout)
// {
// }
///