Struct libunftp::Server[][src]

pub struct Server<Storage, User> where
    Storage: StorageBackend<User>,
    User: UserDetail
{ /* fields omitted */ }

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 tokio::runtime::Runtime;

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

Implementations

impl<Storage, User> Server<Storage, User> where
    Storage: StorageBackend<User> + 'static,
    Storage::Metadata: Metadata,
    User: UserDetail + 'static, 
[src]

pub fn new(sbe_generator: Box<dyn Fn() -> Storage + Send + Sync>) -> Self where
    AnonymousAuthenticator: Authenticator<User>, 
[src]

Construct a new Server with the given StorageBackend generator and an AnonymousAuthenticator

pub fn with_authenticator(
    s: Box<dyn Fn() -> Storage + Send + Sync>,
    authenticator: Arc<dyn Authenticator<User> + Send + Sync>
) -> Self
[src]

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

pub fn authenticator(
    self,
    authenticator: Arc<dyn Authenticator<User> + 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_fs("/tmp")
                 .authenticator(Arc::new(auth::AnonymousAuthenticator{}));

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

Enables FTPS by configuring the path to the certificates file and the private key file. Both should be in PEM format.

Example

use libunftp::Server;

let server = Server::with_fs("/tmp")
             .ftps("/srv/unftp/server.certs", "/srv/unftp/server.key");

pub fn ftps_required<R>(self, for_control_chan: R, for_data_chan: R) -> Self where
    R: Into<FtpsRequired>, 
[src]

Configures whether client connections may use plaintext mode or not.

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_fs("/tmp").greeting("Welcome to my FTP Server");

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

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_fs("/tmp").idle_session_timeout(600);

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

pub fn logger<L: Into<Option<Logger>>>(self, logger: L) -> Self[src]

Sets the structured logger (slog::Logger) to use

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

Enables the collection of prometheus metrics.

Example

use libunftp::Server;

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

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

pub fn passive_host<H: Into<PassiveHost>>(self, host_option: H) -> Self[src]

Specifies how the IP address that libunftp will advertise in response to the PASV command is determined.

Examples

Using a fixed IP specified as a numeric array:

use libunftp::Server;

let server = Server::with_fs("/tmp")
             .passive_host([127,0,0,1]);

Or the same but more explicitly:

use libunftp::{Server,options};
use std::net::Ipv4Addr;

let server = Server::with_fs("/tmp")
             .passive_host(options::PassiveHost::IP(Ipv4Addr::new(127, 0, 0, 1)));

To determine the passive IP from the incoming control connection:

use libunftp::{Server,options};

let server = Server::with_fs("/tmp")
             .passive_host(options::PassiveHost::FromConnection);

Get the IP by resolving a DNS name:

use libunftp::{Server,options};

let server = Server::with_fs("/tmp")
             .passive_host("ftp.myserver.org");

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

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

Example

use libunftp::Server;

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

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

pub fn proxy_protocol_mode(self, external_control_port: u16) -> Self[src]

Enables PROXY protocol mode.

If you use a proxy such as haproxy or nginx, you can enable the PROXY protocol (https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt).

Configure your proxy to enable PROXY protocol encoding for control and data external listening ports, forwarding these connections to the libunFTP listening port in proxy protocol mode.

In PROXY protocol mode, libunftp receives both control and data connections on the listening port. It then distinguishes control and data connections by comparing the original destination port (extracted from the PROXY header) with the port specified as the external_control_port parameter.

Example

use libunftp::Server;

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

pub async fn listen<T: Into<String> + Debug>(
    self,
    bind_address: T
) -> Result<(), ServerError>
[src]

Runs the main ftp process asynchronously. 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::with_fs("/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.

impl Server<Filesystem, DefaultUser>[src]

pub fn with_fs<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_fs("/srv/ftp");

impl<User> Server<Filesystem, User> where
    User: UserDetail + 'static, 
[src]

pub fn with_fs_and_auth<P: Into<PathBuf> + Send + 'static>(
    path: P,
    authenticator: Arc<dyn Authenticator<User> + Send + Sync>
) -> Self
[src]

Create a new Server using the filesystem backend and the specified authenticator

Example

use libunftp::Server;
use libunftp::auth::AnonymousAuthenticator;
use std::sync::Arc;

let server = Server::with_fs_and_auth("/srv/ftp", Arc::new(AnonymousAuthenticator{}));

Trait Implementations

impl<Storage, User> Debug for Server<Storage, User> where
    Storage: StorageBackend<User>,
    User: UserDetail
[src]

Auto Trait Implementations

impl<Storage, User> !RefUnwindSafe for Server<Storage, User>[src]

impl<Storage, User> Send for Server<Storage, User>[src]

impl<Storage, User> Sync for Server<Storage, User>[src]

impl<Storage, User> Unpin for Server<Storage, User>[src]

impl<Storage, User> !UnwindSafe for Server<Storage, User>[src]

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> Instrument for T[src]

impl<T> Instrument 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>, 

impl<T> WithSubscriber for T[src]