Giter Site home page Giter Site logo

rust_async_ftp's People

Contributors

17dec avatar benaryorg avatar bombless avatar daa84 avatar dani-garcia avatar dbrgn avatar dodomorandi avatar emberian avatar little-dude avatar luxed avatar matt2xu avatar mattnenterprise avatar mihaigalos avatar rrevenantt avatar samedhg avatar workanator avatar yackushevas avatar zsck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rust_async_ftp's Issues

Second example on the docs home page doesn't build

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> {
   |                  ^^^^^^^^^^^

FtpStream::retr should allow a more generic error type

FtpStream::retr is very useful, because it allows parsing streaming data from the server and, at the same time, it automatically handles FTP response statuses.

However, there is a major issue related to the error type of the inner function: if you need to perform non-trivial parsing of the remote data, you will end up with a richer set of errors, making FtpStream::retr unusable because FtpError cannot encapsulate all the possible errors anymore.

I propose to change the return type from Result<T, FtpError> to Result<T, E> where E: From<FtpError>. If you like the idea, I will be glad to send you a PR.

Async PUT from stream

I'm trying to use a loop to read data from a file, PUT it to a FTP server and update a progress bar.
tokio::fs::File already implements the R trait trait in put:

pub async fn put<R: AsyncRead + Unpin>(&mut self, filename: &str, r: &mut R) -> Result<()>

So one can just write something like:

let mut file = tokio::fs::File::open(&filename).await.unwrap();
let mut ftp_stream = FtpStream::connect(server_address);
ftp_stream.put(filename, &mut file).await.unwrap();

Qs:

  • how do I instead use a loop to buffer-read from the file and async PUT it to the ftp stream?
  • why does the r in the put signature need to be mutable? I'm kind of confused, since we just read from the file. I see here, r is just copied.

Minor bug in FtpStream::get

Line 298 in FtpStream in the get function is :

self.read_response(status::ABOUT_TO_SEND).await?;

but should be

self.read_response_in(&[status::ABOUT_TO_SEND, status::ALREADY_OPEN]).await?;

(same as in the FtpStream::retr function)

Can this be fixed in the next release?

FtpStream::get() doesn't read status::CLOSING_DATA_CONNECTION

While FtpStream::retr() tries to read a status after reading from the stream, it looks like FtpStream::get() doesn't do this. When we wrote some code that calls get() and completes successfully, then call FtpStream::quit(), it errored out because it read an unexpected error code off the stream:

thread 'main' panicked at 'downloader encountered a critical error: FTP InvalidResponse: Expected code [221], got response: 226 Transfer complete
', downloader/src/bin/downloader.rs:78:10

Maybe it should wrap the BufReader in another type that Derefs to the BufReader but tries to read out the status code on Drop?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.