VoDA.FtpServer
1.0.0
VoDA.FtpServer 是一個簡單的 FTP 伺服器函式庫。該程式庫將與 FTP 協定的互動簡化到事件層級。所有與授權或處理資料相關的伺服器請求都會導致您必須實現的事件。
要啟動伺服器,您需要建立一個 FtpServerBuilder 對象,並使用函數對其進行配置,如下例所示。有關每個功能的更多信息,請參閱配置參數。配置完成後,呼叫Build()
函數建立伺服器。
測試項目中給出了使用檔案系統的 FTP 伺服器範例。
var server = new FtpServerBuilder ( )
. ListenerSettings ( ( config ) =>
{
config . Port = 21 ; // enter the port
config . ServerIp = System . Net . IPAddress . Any ;
} )
. Log ( ( config ) =>
{
config . Level = LogLevel . Information ; // enter log level. Default: Information
} )
. Certificate ( ( config ) =>
{
config . CertificatePath = ". \ server.crt" ;
config . CertificateKey = ". \ server.key" ;
} )
. Authorization ( ( config ) =>
{
config . UseAuthorization = true ; // enable or disable authorization
config . UsernameVerification += ( username ) => { .. . } ; // username verification
config . PasswordVerification += ( username , password ) => { .. . } ; //verification of username and password
} )
. FileSystem ( ( fs ) =>
{
fs . OnDeleteFile += ( client , path ) => { .. . } ; // delete file event
fs . OnRename += ( client , from , to ) => { .. . } ; // rename item event
fs . OnDownload += ( client , path ) => { .. . } ; // download file event
fs . OnGetList += ( client , path ) => { .. . } ; // get items in folder event
fs . OnExistFile += ( client , path ) => { .. . } ; // file check event
fs . OnExistFoulder += ( client , path ) => { .. . } ; // folder check event
fs . OnCreate += ( client , path ) => { .. . } ; // file creation event
fs . OnAppend += ( client , path ) => { .. . } ; // append file event
fs . OnDeleteFolder += ( client , path ) => { .. . } ; // remove folder event
fs . OnUpload += ( client , path ) => { .. . } ; // upload file event
fs . OnGetFileSize += ( client , path ) => { .. . } ; // get file size event
fs . OnGetFileModificationTime += ( client , path ) => { .. . } ; // returns the last modified date of the file
} )
. Build ( ) ;
// Start FTP-serer
server . StartAsync ( System . Threading . CancellationToken . None ) . Wait ( ) ;
或者您可以使用您自己的從上下文類別繼承的類別。下面是一個例子。
在此範例中,類別MyAuthorization
繼承自VoDA.FtpServer.Contexts.AuthorizationOptionsContext
,類別MyFileSystem
繼承自VoDA.FtpServer.Contexts.FileSystemOptionsContext
var server = new FtpServerBuilder ( )
. ListenerSettings ( ( config ) =>
{
config . Port = 21 ; // enter the port
config . ServerIp = System . Net . IPAddress . Any ;
} )
. Log ( ( config ) =>
{
config . Level = LogLevel . Information ; // enter log level. Default: Information
} )
. Certificate ( ( config ) =>
{
config . CertificatePath = ". \ server.crt" ;
config . CertificateKey = ". \ server.key" ;
} )
. Authorization < MyAuthorization > ( )
. FileSystem < MyFileSystem > ( )
. Build ( ) ;
// Start FTP-serer
server . StartAsync ( System . Threading . CancellationToken . None ) . Wait ( ) ;
完整範例請參閱測試項目。