[][src]Struct libunftp::Server

pub struct Server<S: Send + Sync, 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::new_with_fs_root("/srv/ftp");
rt.spawn(server.listen("127.0.0.1:2121"));
// ...
drop(rt);

Methods

impl Server<Filesystem, AnonymousUser>[src]

pub fn new_with_fs_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::new_with_fs_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 + Sync>) -> 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::new_with_fs_root("/tmp").greeting("Welcome to my FTP Server");

// Or instead if you prefer:
let mut server = Server::new_with_fs_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::new_with_fs_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::new_with_fs_root("/tmp").passive_ports(49152..65535);


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

pub fn ftps<P: Into<PathBuf>, T: Into<String>>(
    self,
    certs_file: P,
    password: T
) -> Self
[src]

Configures the path to the certificates file (DER-formatted PKCS #12 archive) and the associated password for the archive in order to configure FTPS.

Example

use libunftp::Server;

let mut server = Server::new_with_fs_root("/tmp").ftps("/srv/unftp/server-certs.pfx", "thepassword");

pub fn 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::new_with_fs_root("/tmp").metrics();

// Or instead if you prefer:
let mut server = Server::new_with_fs_root("/tmp");
server.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::new_with_fs_root("/tmp").idle_session_timeout(600);

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

pub async fn listen<T: Into<String>>(self, bind_address: T)[src]

Runs the main ftp process asyncronously. Should be started in a async runtime context.

Example

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

let mut rt = Runtime::new().unwrap();
let server = Server::new_with_fs_root("/srv/ftp");
rt.spawn(server.listen("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> 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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,