[][src]Module libunftp::storage

Contains the StorageBackend trait and its bundled implementations that can used by the Server.

You can define your own implementation to integrate your FTP(S) server with whatever backend you need. To create a new storage back-end:

  1. Declare a dependency on the async-trait crate
async-trait = "0.1.42"
  1. Implement the StorageBackend trait and optionally the Metadata trait:
use async_trait::async_trait;
use libunftp::storage::{Fileinfo, Metadata, Result, StorageBackend};
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use libunftp::auth::DefaultUser;

#[derive(Debug)]
pub struct Vfs {}

impl Vfs {
  fn new() -> Vfs { Vfs{} }
}

#[async_trait]
impl libunftp::storage::StorageBackend<DefaultUser> for Vfs {
    type Metadata = std::fs::Metadata;

    async fn metadata<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        path: P,
    ) -> Result<Self::Metadata> {
        unimplemented!()
    }

    async fn list<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        path: P,
    ) -> Result<Vec<Fileinfo<PathBuf, Self::Metadata>>>
    where
        <Self as StorageBackend<DefaultUser>>::Metadata: Metadata,
    {
        unimplemented!()
    }

    async fn get<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        path: P,
        start_pos: u64,
    ) -> Result<Box<dyn tokio::io::AsyncRead + Send + Sync + Unpin>> {
        unimplemented!()
    }

    async fn put<
        P: AsRef<Path> + Send + Debug,
        R: tokio::io::AsyncRead + Send + Sync + Unpin + 'static,
    >(
        &self,
        user: &Option<DefaultUser>,
        input: R,
        path: P,
        start_pos: u64,
    ) -> Result<u64> {
        unimplemented!()
    }

    async fn del<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        path: P,
    ) -> Result<()> {
        unimplemented!()
    }

    async fn mkd<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        path: P,
    ) -> Result<()> {
        unimplemented!()
    }

    async fn rename<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        from: P,
        to: P,
    ) -> Result<()> {
        unimplemented!()
    }

    async fn rmd<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        path: P,
    ) -> Result<()> {
        unimplemented!()
    }

    async fn cwd<P: AsRef<Path> + Send + Debug>(
        &self,
        user: &Option<DefaultUser>,
        path: P,
    ) -> Result<()> {
        unimplemented!()
    }
}
  1. Initialize it with the Server:
let vfs_provider = Box::new(|| Vfs::new());
let server = libunftp::Server::new(vfs_provider);

Modules

cloud_storage

A StorageBackend that uses Cloud Storage from Google

filesystem

A StorageBackend that uses a local filesystem, like a traditional FTP server.

Structs

Error

The Error returned by storage backends. Storage backend implementations should choose the ErrorKind chosen for errors carefully since that will determine what is returned to the FTP client.

Fileinfo

Fileinfo contains the path and Metadata of a file.

Permissions

Represents the permissions of a FTP File

Enums

ErrorKind

The ErrorKind variants that can be produced by the StorageBackend implementations.

Constants

FEATURE_RESTART

Tells if STOR/RETR restarts are supported by the storage back-end i.e. starting from a different byte offset.

Traits

Metadata

Represents the metadata of a FTP File

StorageBackend

The StorageBackend trait defines a common interface to different storage backends for our FTP Server, e.g. for a Filesystem or Google Cloud Storage.

Type Definitions

Result

Result type used by traits in this module