[−][src]Struct libunftp::Server
An instance of an FTP(S) server. It aggregates an Authenticator
that will be used
for authentication, and a StorageBackend
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<S, U> Server<S, U> where
S: StorageBackend<U> + 'static,
S::Metadata: Metadata,
U: UserDetail + 'static,
[src]
S: StorageBackend<U> + 'static,
S::Metadata: Metadata,
U: UserDetail + 'static,
pub fn new(sbe_generator: Box<dyn Fn() -> S + Send + Sync>) -> Self where
AnonymousAuthenticator: Authenticator<U>,
[src]
AnonymousAuthenticator: Authenticator<U>,
Construct a new Server
with the given StorageBackend
generator and an AnonymousAuthenticator
pub fn with_authenticator(
s: Box<dyn Fn() -> S + Send + Sync>,
authenticator: Arc<dyn Authenticator<U> + Send + Sync>
) -> Self
[src]
s: Box<dyn Fn() -> S + Send + Sync>,
authenticator: Arc<dyn Authenticator<U> + Send + Sync>
) -> Self
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<U> + Send + Sync>
) -> Self
[src]
self,
authenticator: Arc<dyn Authenticator<U> + Send + Sync>
) -> Self
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]
R: Into<FtpsRequired>,
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]
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 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<U> Server<Filesystem, U> where
U: UserDetail + 'static,
[src]
U: UserDetail + 'static,
pub fn with_fs_and_auth<P: Into<PathBuf> + Send + 'static>(
path: P,
authenticator: Arc<dyn Authenticator<U> + Send + Sync>
) -> Self
[src]
path: P,
authenticator: Arc<dyn Authenticator<U> + Send + Sync>
) -> Self
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<S, U> Debug for Server<S, U> where
S: StorageBackend<U>,
U: UserDetail,
[src]
S: StorageBackend<U>,
U: UserDetail,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,