在做项目的时候,需要用到FTP功能。
public class FtpHelper
{
private const string LogModule = nameof(FtpHelper);
public string Username { get; }
public string Password { get; }
public string Url { get; }
public FtpHelper()
{
this.Username = "admin";
this.Password = string.Empty;
}
public FtpHelper(string username, string password,string url)
{
this.Username = username ?? string.Empty;
this.Password = password ?? string.Empty;
this.Url = url ?? string.Empty;
}
/// <summary>
/// 获取当前目录下文件列表
/// </summary>
/// <returns>文件列表</returns>
public List<string> GetFileList()
{
List<string> result = new List<string>();
FtpWebRequest request; string url = string.Empty;
try
{
url = Url;
request = CreateRequest(url,WebRequestMethods.Ftp.ListDirectory);
}
catch (UriFormatException ex)
{
throw new UriFormatException("FTP地址格式错误:" + url, ex);
}
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse(