Jc.FTP 2.0.8

dotnet add package Jc.FTP --version 2.0.8
NuGet\Install-Package Jc.FTP -Version 2.0.8
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.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jc.FTP --version 2.0.8
#r "nuget: Jc.FTP, 2.0.8"
#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.8

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

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/ftpfiles";
     
     //密钥
     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"),
         new KeyValuePair<string, string>("CEX", "1234")
     });
     
     
     //IP节点
     var endpoiint = new IPEndPointData
     {
         Address = IPAddress.Any,
         Port = 21,
     };
   
     //启动服务:支持多个重载
     var server = new JcFTPServer(
         endpoiint,
         fileProviderFactory,
         authenticator
     );
     
     //增加连接监听
     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, string message,IPEndPoint remoteAddress)
 {
     Console.WriteLine($"Command>{command}:Message>{message}:{remoteAddress.Address}");
 }

 void FtpReply(string replyCode,string message, IPEndPoint remoteAddress)
 {
     Console.WriteLine($"Reply>{replyCode}:{message}:{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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 231 3/7/2023
2.0.7 417 5/13/2022
2.0.6 400 4/15/2022
2.0.5 391 4/15/2022
2.0.4 391 4/15/2022
2.0.3 397 4/15/2022
2.0.2 405 4/15/2022
2.0.1 385 4/8/2022
1.0.1 403 3/4/2022