pub struct Server<Storage, User>where
Storage: StorageBackend<User>,
User: UserDetail,{ /* private fields */ }
Expand description
An instance of an FTP(S) server. It aggregates an Authenticator
implementation that will be used for authentication, and a StorageBackend
implementation that will be used as the virtual file system.
The server can be started with the listen
method.
§Example
use libunftp::Server;
use unftp_sbe_fs::ServerExt;
use tokio::runtime::Runtime;
let mut rt = Runtime::new().unwrap();
rt.spawn(async {
let server = Server::with_fs("/srv/ftp").build().unwrap();
server.listen("127.0.0.1:2121").await.unwrap()
});
Implementations§
Source§impl<Storage, User> Server<Storage, User>where
Storage: StorageBackend<User> + 'static,
Storage::Metadata: Metadata,
User: UserDetail + 'static,
impl<Storage, User> Server<Storage, User>where
Storage: StorageBackend<User> + 'static,
Storage::Metadata: Metadata,
User: UserDetail + 'static,
Sourcepub fn new(
sbe_generator: Box<dyn Fn() -> Storage + Send + Sync>,
) -> ServerBuilder<Storage, User>where
AnonymousAuthenticator: Authenticator<User>,
👎Deprecated since 0.19.0: use ServerBuilder::new instead
pub fn new(
sbe_generator: Box<dyn Fn() -> Storage + Send + Sync>,
) -> ServerBuilder<Storage, User>where
AnonymousAuthenticator: Authenticator<User>,
Construct a new ServerBuilder
with the given StorageBackend
generator and an AnonymousAuthenticator
Sourcepub async fn listen<T: Into<String> + Debug>(
self,
bind_address: T,
) -> Result<(), ServerError>
pub async fn listen<T: Into<String> + Debug>( self, bind_address: T, ) -> Result<(), ServerError>
Runs the main FTP process asynchronously. Should be started in a async runtime context.
§Example
use libunftp::Server;
use unftp_sbe_fs::ServerExt;
use tokio::runtime::Runtime;
let mut rt = Runtime::new().unwrap();
rt.spawn(async {
let server = Server::with_fs("/srv/ftp").build().unwrap();
server.listen("127.0.0.1:2121").await
});
// ...
drop(rt);
Sourcepub async fn service(
self,
tcp_stream: TcpStream,
) -> Result<(), ControlChanError>
pub async fn service( self, tcp_stream: TcpStream, ) -> Result<(), ControlChanError>
Service a newly established connection as a control connection.
Use this method instead of listen
if you want to listen for and accept
new connections yourself, instead of using libunftp to do it.
Sourcepub fn with_authenticator(
sbe_generator: Box<dyn Fn() -> Storage + Send + Sync>,
authenticator: Arc<dyn Authenticator<User> + Send + Sync>,
) -> ServerBuilder<Storage, User>
👎Deprecated since 0.19.0: use ServerBuilder::with_authenticator instead
pub fn with_authenticator( sbe_generator: Box<dyn Fn() -> Storage + Send + Sync>, authenticator: Arc<dyn Authenticator<User> + Send + Sync>, ) -> ServerBuilder<Storage, User>
Construct a new ServerBuilder
with the given StorageBackend
generator and Authenticator
. The other parameters will be set to defaults.