[][src]Struct libunftp::server::Server

pub struct Server<S, U: Send + Sync> where
    S: StorageBackend<U>, 
{ /* fields omitted */ }

An instance of a FTP server. It contains a reference to an Authenticator that will be used for authentication, and a StorageBackend that will be used as the storage backend.

The server can be started with the listen method.

Example

use libunftp::Server;
use tokio::runtime::Runtime;

let mut rt = Runtime::new().unwrap();
let server = Server::with_root("/srv/ftp");
rt.spawn(server.listener("127.0.0.1:2121"));
// ...
drop(rt);

Methods

impl Server<Filesystem, AnonymousUser>[src]

pub fn with_root<P: Into<PathBuf> + Send + 'static>(path: P) -> Self[src]

Create a new Server with the given filesystem root.

Example

use libunftp::Server;

let server = Server::with_root("/srv/ftp");

impl<S, U: Send + Sync + 'static> Server<S, U> where
    S: 'static + StorageBackend<U> + Sync + Send,
    S::File: AsyncRead + Send,
    S::Metadata: Metadata
[src]

pub fn new(s: Box<dyn Fn() -> S + Send>) -> Self where
    AnonymousAuthenticator: Authenticator<U>, 
[src]

Construct a new Server with the given StorageBackend. The other parameters will be set to defaults.

pub fn greeting(self, greeting: &'static str) -> Self[src]

Set the greeting that will be sent to the client after connecting.

Example

use libunftp::Server;

// Use it in a builder-like pattern:
let mut server = Server::with_root("/tmp").greeting("Welcome to my FTP Server");

// Or instead if you prefer:
let mut server = Server::with_root("/tmp");
server.greeting("Welcome to my FTP Server");

pub fn authenticator(
    self,
    authenticator: Arc<dyn Authenticator<U> + Send + Sync>
) -> Self
[src]

Set the Authenticator that will be used for authentication.

Example

use libunftp::{auth, auth::AnonymousAuthenticator, Server};
use std::sync::Arc;

// Use it in a builder-like pattern:
let mut server = Server::with_root("/tmp")
                 .authenticator(Arc::new(auth::AnonymousAuthenticator{}));

pub fn passive_ports(self, range: Range<u16>) -> Self[src]

Set the range of passive ports that we'll use for passive connections.

Example

use libunftp::Server;

// Use it in a builder-like pattern:
let mut server = Server::with_root("/tmp").passive_ports(49152..65535);


// Or instead if you prefer:
let mut server = Server::with_root("/tmp");
server.passive_ports(49152..65535);

pub fn certs<P: Into<PathBuf>>(self, certs_file: P, key_file: P) -> Self[src]

Configures the path to the certificates file (PEM format) and the associated private key file in order to configure FTPS.

Example

use libunftp::Server;

let mut server = Server::with_root("/tmp").certs("/srv/unftp/server-certs.pem", "/srv/unftp/server-key.pem");

pub fn with_metrics(self) -> Self[src]

Enable the collection of prometheus metrics.

Example

use libunftp::Server;

// Use it in a builder-like pattern:
let mut server = Server::with_root("/tmp").with_metrics();

// Or instead if you prefer:
let mut server = Server::with_root("/tmp");
server.with_metrics();

pub fn idle_session_timeout(self, secs: u64) -> Self[src]

Set the idle session timeout in seconds. The default is 600 seconds.

Example

use libunftp::Server;

// Use it in a builder-like pattern:
let mut server = Server::with_root("/tmp").idle_session_timeout(600);

// Or instead if you prefer:
let mut server = Server::with_root("/tmp");
server.idle_session_timeout(600);

pub fn listener<'a>(
    self,
    addr: &str
) -> Box<dyn Future<Item = (), Error = ()> + Send + 'a>
[src]

Returns a tokio future that is the main ftp process. Should be started in a tokio context.

Example

use libunftp::Server;
use tokio::runtime::Runtime;

let mut rt = Runtime::new().unwrap();
let server = Server::with_root("/srv/ftp");
rt.spawn(server.listener("127.0.0.1:2121"));
// ...
drop(rt);

Panics

This function panics when called with invalid addresses or when the process is unable to bind() to the address.

Auto Trait Implementations

impl<S, U> !RefUnwindSafe for Server<S, U>

impl<S, U> Send for Server<S, U>

impl<S, U> !Sync for Server<S, U>

impl<S, U> Unpin for Server<S, U>

impl<S, U> !UnwindSafe for Server<S, U>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.