veeso / suppaftp

a super FTP/FTPS client library for Rust with support for both passive and active mode
Apache License 2.0
121 stars 31 forks source link

Implicit SSL example #14

Closed IsaacJReay closed 2 years ago

IsaacJReay commented 2 years ago

Hello developers, I recently used your crate and found it to be very interesting. Everything just works. However, I cannot seems to find way to connect when using implicit ssl settings. Filezilla seems to be working fine. Whenever I tried to connect it via the explicit method, it hanged at ftpstream::connect. Maybe this isn't the right way to connect. Could you show me how to do it? Thanks

veeso commented 2 years ago

I don't think it's supported at the moment, but I can work on it

IsaacJReay commented 2 years ago

Really appreciate your efforts. Is asking for ETA ok? Thanks

veeso commented 2 years ago

I can try to release it in two days

veeso commented 2 years ago

The feature is now available in suppaftp 4.3.0, please see the example below:

use suppaftp::FtpStream;
use suppaftp::native_tls::{TlsConnector, TlsStream};
use std::path::Path;
// Create a TlsConnector
// NOTE: For custom options see <https://docs.rs/native-tls/0.2.6/native_tls/struct.TlsConnectorBuilder.html>
let mut ctx = TlsConnector::new().unwrap();
let mut ftp_stream = FtpStream::connect_secure_implicit("127.0.0.1:990", ctx, "localhost").unwrap();

In order to enable the connect_secure_implicit method, you have to compile suppaftp with the deprecated feature.

yyyymux commented 2 years ago

Hello, Developer and Landlord,when i called into_secure, it hanged at " SecureError("error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed: " , How to add certificates for clients? thank you!

veeso commented 2 years ago

You should try some options of the tls builder:

let ctx = TlsConnector::builder()
                .danger_accept_invalid_certs(true)
                .danger_accept_invalid_hostnames(true)
                .build()
yyyymux commented 2 years ago

thanks!

svet-b commented 1 year ago

Is this still supported in the latest version? With the "deprecated", "native-tls" features enabled, and the sample code

use suppaftp::FtpStream;
use suppaftp::native_tls::{TlsConnector, TlsStream};

let mut ctx = TlsConnector::new().unwrap();
let mut ftp_stream = FtpStream::connect_secure_implicit("127.0.0.1:990", ctx, "localhost").unwrap();

I get the error

error[E0277]: the trait bound `native_tls::TlsConnector: suppaftp::sync_ftp::tls::TlsConnector` is not satisfied
   --> src/interfaces/ftp.rs:63:82
    |
63  |         let mut ftp_stream = FtpStream::connect_secure_implicit("127.0.0.1:990", ctx, "localhost").unwrap();
    |                              ----------------------------------                  ^^^ the trait `suppaftp::sync_ftp::tls::TlsConnector` is not implemented for `native_tls::TlsConnector`
    |                              |
    |                              required by a bound introduced by this call
    |
    = help: the trait `suppaftp::sync_ftp::tls::TlsConnector` is implemented for `NativeTlsConnector`
note: required by a bound in `ImplFtpStream::<T>::connect_secure_implicit`
   --> /Users/svet/.cargo/registry/src/github.com-1ecc6299db9ec823/suppaftp-5.1.1/src/sync_ftp/mod.rs:184:29
    |
184 |         tls_connector: impl TlsConnector<Stream = T> + 'static,
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ImplFtpStream::<T>::connect_secure_implicit`

If I follow the "help" hint and instead set ctx to

let mut ctx = NativeTlsConnector::from(TlsConnector::new().unwrap());

I get a type mismatch on it:

error[E0271]: type mismatch resolving `<NativeTlsConnector as suppaftp::sync_ftp::tls::TlsConnector>::Stream == suppaftp::sync_ftp::tls::NoTlsStream`
   --> src/interfaces/ftp.rs:64:82
    |
64  |         let mut ftp_stream = FtpStream::connect_secure_implicit("127.0.0.1:990", ctx, "localhost").unwrap();
    |                              ----------------------------------                  ^^^ expected struct `suppaftp::sync_ftp::tls::NoTlsStream`, found struct `suppaftp::sync_ftp::tls::native_tls::NativeTlsStream`
    |                              |
    |                              required by a bound introduced by this call

Any hints as to how to go about this?

veeso commented 1 year ago

@svet-b you're using the wrong type. You need to use NativeTlsFtpStream and not FtpStream

svet-b commented 1 year ago

Thanks for the quick response @veeso - really appreciate your help here!

The following indeed seems to work 👍

use suppaftp::{NativeTlsConnector, NativeTlsFtpStream};
use suppaftp::native_tls::TlsConnector;

let mut ctx = NativeTlsConnector::from(TlsConnector::new().unwrap());
let mut ftp_stream = NativeTlsFtpStream::connect_secure_implicit("127.0.0.1:990", ctx, "localhost").unwrap();