C# 实现FTP上传和下载
2021-04-27 09:27
标签:result .sh ssi ring method enables sts ftp下载 应用 初学C# 需要用到FTP下载文件,在这里记录一下。 具体FtpWebRequest查看文档: C# 实现FTP上传和下载 标签:result .sh ssi ring method enables sts ftp下载 应用 原文地址:http://www.cnblogs.com/anonymous-qsh/p/7858361.htmlC# 实现FTP下载文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Threading;
namespace FtpUtils
{
class FtpHelper
{
// 默认常量定义
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)
{
}
///
https://msdn.microsoft.com/zh-cn/library/system.net.ftpwebrequest.usepassive(v=vs.110).aspx
下一篇:C#压缩文件