This is an automated email from the ASF dual-hosted git repository. junouyang pushed a commit to branch bump/suppaftp in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit dd8c984e003e52d858dc950e7fad2ccef889eaa8 Author: owl <[email protected]> AuthorDate: Wed Nov 15 22:38:17 2023 +0800 fix: let ftp service to suppaftp 5.2 API --- Cargo.lock | 13 +++++++++++++ core/Cargo.toml | 2 ++ core/src/services/ftp/backend.rs | 13 +++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce7263709..02bf97e81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,6 +297,18 @@ dependencies = [ "event-listener", ] +[[package]] +name = "async-native-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9343dc5acf07e79ff82d0c37899f079db3534d99f189a1837c8e549c99405bec" +dependencies = [ + "futures-util", + "native-tls", + "thiserror", + "url", +] + [[package]] name = "async-recursion" version = "0.3.2" @@ -6586,6 +6598,7 @@ version = "5.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "653aa9a6ebc0446a2d5c2be5b698b48a3192c7a098d0ed9a7c232e3a6340f091" dependencies = [ + "async-native-tls", "async-std", "async-tls 0.12.0", "async-trait", diff --git a/core/Cargo.toml b/core/Cargo.toml index 10bbd2485..85aa539b4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -51,6 +51,7 @@ default = [ "services-webdav", "services-webhdfs", "services-azfile", + "services-ftp", ] # Build docs or not. @@ -291,6 +292,7 @@ sled = { version = "0.34.7", optional = true } suppaftp = { version = "5.2", default-features = false, features = [ "async-secure", "async-rustls", + "async-native-tls", ], optional = true } tikv-client = { version = "0.2.0", optional = true } tokio = "1.27" diff --git a/core/src/services/ftp/backend.rs b/core/src/services/ftp/backend.rs index 787da112f..d0d9d9bb9 100644 --- a/core/src/services/ftp/backend.rs +++ b/core/src/services/ftp/backend.rs @@ -21,7 +21,6 @@ use std::fmt::Formatter; use std::str; use std::str::FromStr; -use async_tls::TlsConnector; use async_trait::async_trait; use bb8::PooledConnection; use bb8::RunError; @@ -29,11 +28,14 @@ use futures::AsyncRead; use futures::AsyncReadExt; use http::Uri; use log::debug; +use suppaftp::AsyncNativeTlsFtpStream; use suppaftp::list::File; use suppaftp::types::FileType; use suppaftp::types::Response; use suppaftp::FtpError; -use suppaftp::FtpStream; +use suppaftp::ImplAsyncFtpStream; +use suppaftp::async_native_tls::TlsConnector; +use suppaftp::AsyncNativeTlsConnector; use suppaftp::Status; use tokio::sync::OnceCell; @@ -213,16 +215,15 @@ pub struct Manager { #[async_trait] impl bb8::ManageConnection for Manager { - type Connection = FtpStream; + type Connection = AsyncNativeTlsFtpStream; type Error = FtpError; async fn connect(&self) -> std::result::Result<Self::Connection, Self::Error> { - let stream = FtpStream::connect(&self.endpoint).await?; - + let stream = ImplAsyncFtpStream::connect(&self.endpoint).await?; // switch to secure mode if ssl/tls is on. let mut ftp_stream = if self.enable_secure { stream - .into_secure(TlsConnector::default().into(), &self.endpoint) + .into_secure(AsyncNativeTlsConnector::from(TlsConnector::new()), &self.endpoint) .await? } else { stream
