dani-garcia / rust_async_ftp

Fork of https://crates.io/crates/ftp with tokio async support
Apache License 2.0
21 stars 14 forks source link

Second example on the docs home page doesn't build #18

Open sp1ff opened 1 year ago

sp1ff commented 1 year ago

Example:

use async_ftp::FtpStream;
use std::convert::TryFrom;
use tokio_rustls::rustls::{ClientConfig, RootCertStore, ServerName};

#[tokio::main]
async fn main() {
    let ftp_stream = FtpStream::connect("lettir.orangewebsite.com: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("lettir.orangewebsite.com").expect("invalid DNS name");

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

gives:

error[E0308]: arguments to this function are incorrect
  --> src/main.rs:20:37
   |
20 |     let mut ftp_stream = ftp_stream.into_secure(conf, domain).await.unwrap();
   |                                     ^^^^^^^^^^^ ----  ------ expected enum `rustls::client::client_conn::ServerName`, found enum `tokio_rustls::rustls::ServerName`
   |                                                 |
   |                                                 expected struct `rustls::client::client_conn::ClientConfig`, found struct `ClientConfig`
   |
   = note: perhaps two different versions of crate `rustls` are being used?
   = note: perhaps two different versions of crate `rustls` are being used?
note: associated function defined here
  --> /home/mgh/.cargo/registry/src/github.com-1ecc6299db9ec823/async_ftp-6.0.0/src/ftp.rs:87:18
   |
87 |     pub async fn into_secure(mut self, config: ClientConfig, domain: ServerName) -> Result<FtpStream> {
   |                  ^^^^^^^^^^^