Expand description

ftp is an FTP client written in Rust.

Usage

Here is a basic usage example:

use ftp_rs::FtpClient;
async {
  let mut ftp_client = FtpClient::connect("192.168.32.204:21").await.unwrap_or_else(|err|
      panic!("{}", err)
  );
  let _ = ftp_client.quit();
};

FTPS

The client supports FTPS on demand. To enable it the client should be compiled with feature openssl enabled what requires openssl dependency.

The client uses explicit mode for connecting FTPS what means you should connect the server as usually and then switch to the secure mode (TLS is used). For better security it’s the good practice to switch to the secure mode before authentication.

FTPS Usage

use std::convert::TryFrom;
use std::path::Path;
use ftp_rs::FtpClient;
use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};

async {
  let ftp_client = FtpClient::connect("192.168.32.204:21").await.unwrap();
   
  let mut root_store = RootCertStore::empty();
  // root_store.add_pem_file(...);
  let conf = ClientConfig::builder().with_safe_defaults().with_root_certificates(root_store).with_no_client_auth();
  let domain = ServerName::try_from("www.cert-domain.com").expect("invalid DNS name");

  // Switch to the secure mode
  let mut ftp_client = ftp_client.into_secure(conf, domain).await.unwrap();
  ftp_client.login("anonymous", "anonymous").await.unwrap();
  // Do other secret stuff
  // Switch back to the insecure mode (if required)
  let mut ftp_client = ftp_client.into_insecure().await.unwrap();
  // Do all public stuff
  let _ = ftp_client.quit().await;
};

Re-exports

pub use self::types::FtpError;

Modules

The set of valid values for FTP commands

Structs

Enums

Constants

Traits