Jc.FTP 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Jc.FTP --version 2.0.2                
NuGet\Install-Package Jc.FTP -Version 2.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jc.FTP" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jc.FTP --version 2.0.2                
#r "nuget: Jc.FTP, 2.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jc.FTP as a Cake Addin
#addin nuget:?package=Jc.FTP&version=2.0.2

// Install Jc.FTP as a Cake Tool
#tool nuget:?package=Jc.FTP&version=2.0.2                

Jc.FTP

ftp服务,客户端模块

服务端

创建FTP服务

 void FTPServer()
 {
     //the PKCS7 certificate file 
     string CertificatePath=null;
     
     //the PKCS7 certificate password
     string CertificatePassword=null;
     
     //根目录
     string BasePath = "/Users/jackerkun/Downloads";
     
     //密钥
     X509Certificate certificate = null;
     if (!string.IsNullOrEmpty(CertificatePath))
     {
         certificate = new X509Certificate(CertificatePath, CertificatePassword);
     }

     //文件夹对象
     var fileProviderFactory = new SimpleFileProviderFactory(BasePath);
     
     //数据链接对象
     var dataConnectionFactory =
         certificate == null
             ? new LocalDataConnectionFactory()
             : (IDataConnectionFactory) new SslLocalDataConnectionFactory(certificate);
     
     //SSL安全认证对象
     var controlConnectionSslFactory = certificate == null ? null : new ControlConnectionSslFactory(certificate);

     //匿名用户
     //var authenticator = new AnonymousAuthenticator();
     
     //单用户
     //var authenticator = new SingleAuthenticator("admin", "admin"); 
     
     //多用户
     var authenticator = new MultiAuthenticator(new List<KeyValuePair<string, string>>()
     {
         new KeyValuePair<string, string>("admin", "admin"),
         new KeyValuePair<string, string>("CEX", "CEX")
     });
     
     //IP节点
     var endpoiint = new IPEndPointData
     {
         Address = IPAddress.Any,
         Port = 21,
     };
   
     //启动服务:支持多个重载
     var server = new JcFTPServer(
         endpoiint,
         fileProviderFactory,
         authenticator,
         dataConnectionFactory,
         controlConnectionSslFactory
         );
     
     //增加连接监听
     server.Tracer.UserConnected += new FtpTracer.UserEventHandler(FtpConnect);
     //增加断开监听
     server.Tracer.UserDisconnected += new FtpTracer.UserEventHandler(FtpDisconnected);
     //增加指令监听
     server.Tracer.CommandInvoked += new FtpTracer.FtpCommandInvokedHandler(FtpCommand);
     //增加回复指令监听
     server.Tracer.ReplyInvoked += new FtpTracer.FtpReplyInvokedHandler(FtpReply);
     var cancelSource = new CancellationTokenSource();
     var serverInter= server.RunAsync(cancelSource.Token)
         .ContinueWith(result =>
         {
             if (result.Exception != null)
             {
                 Console.WriteLine($"Server at {endpoiint} has stopped because of: \n{result.Exception.Message}\n");
             }
             else
             {
                 Console.WriteLine($"Server at {endpoiint} has stopped successfully.");
             }
         });
     
     //停止
     //cancelSource.Cancel();
     //Task.WaitAll(serverInter);

     //获取已经链接的ip
     //var connectUsers=server.Tracer.ConnectedUsersView;
 }
 
 void FtpDisconnected(IPEndPoint ipEndPoint)
 {
     Console.WriteLine("Disconnected>"+ipEndPoint.Address);
 }

 void FtpConnect(IPEndPoint ipEndPoint)
 {
     Console.WriteLine("Connected>"+ipEndPoint.Address);
 }
 
 void FtpCommand(string command, IPEndPoint remoteAddress)
 {
     Console.WriteLine($"Command>{command}:{remoteAddress.Address}");
 }

 void FtpReply(string replyCode, IPEndPoint remoteAddress)
 {
     Console.WriteLine($"Reply>{replyCode}:{remoteAddress.Address}");
 } 

客户端

void FTPTest()
{
    JcFTPClient _ftphelper = new JcFTPClient(new Uri("ftp://127.0.0.1:21"), "CEX", "CEX");
    //添加事件
   _ftphelper.FtpError              += Ftphelper_FtpError;
   _ftphelper.FileDownloadCompleted += Ftphelper_FileDownloadCompleted;
   _ftphelper.FileDownloading       += Ftphelper_FileDownloading;
   _ftphelper.FileUploadCompleted   += Ftphelper_FileUploadCompleted;
   _ftphelper.FileUploading         += Ftphelper_FileUploading;
    //开始链接
    if (true == _ftphelper.Connect())
    {
       //切换目录
       _ftphelper.GotoDirectory("/");
       var res = _ftphelper.ListFilesAndFolders();
       var filDownload= _ftphelper.DownloadFileAsync(res[0].FullName, "/Users/jackerkun/Downloads/1.docx", false);
    }
}

//文件下载中回调
void Ftphelper_FileDownloading(object sender, EventArgs e)
{
}

//文件上传中回调
void Ftphelper_FileUploading(object sender, EventArgs e)
{
}

//错误回调
void Ftphelper_FtpError(object sender, EventArgs e)
{
}

//文件下载完成
void Ftphelper_FileDownloadCompleted(object sender, EventArgs e)
{
}

//文件上传完成
void Ftphelper_FileUploadCompleted(object sender, EventArgs e)
{
}

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.8 279 3/7/2023
2.0.7 443 5/13/2022
2.0.6 428 4/15/2022
2.0.5 420 4/15/2022
2.0.4 416 4/15/2022
2.0.3 423 4/15/2022
2.0.2 435 4/15/2022
2.0.1 411 4/8/2022
1.0.1 433 3/4/2022