首先在Nuget package下载下面的dll,第三方封装好的:
using FluentFTP;
using System;
using System.IO;
using System.Net;
namespace Test
{
public class FTPHelper
{
private FtpClient ftp;
public bool Connected {
get {
return ftp.IsConnected; } }
public void InitClient(string server, string port, string user, string pwd)
{
try
{
ftp = new FtpClient(server, Int32.Parse(port), new NetworkCredential(user, pwd));
}
catch (Exception ex)
{
throw ex;
}
}
public bool Connect()
{
try
{
if (!Connected)
{
ftp.Connect();
}
return true;
}
catch (Exception ex)
{
throw ex;
return false;
}
}
public void Disconnect()
{
try
{
if (ftp != null && Connected)
{
ftp.Disconnect();
}
}
catch (Exception ex)