This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new dac19249b3 chore(services/ftp): upgrade suppaftp to 13.0.0 (#8768)
dac19249b3 is described below

commit dac19249b33865c87ea005ef885d63d4a605daeb
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 08:54:59 2026 +0800

    chore(services/ftp): upgrade suppaftp to 13.0.0 (#8768)
    
    * chore(services/ftp): upgrade suppaftp to 13.0.0
    
    Replace finalize_put_stream with TransferStream::finish() and keep the 
cancel-safe CloseState transitions: mark the writer Failed before awaiting 
flush/finish, and advance to Rename only after finish succeeds.
    
    Read from TransferStream directly, enforce the requested range locally, and 
finish the transfer at EOF or when the range is satisfied.
    
    Update Cargo.lock only for suppaftp. suppaftp 13 uses jiff 1.0.1, which 
opendal-core already uses, so no duplicate jiff version is introduced.
    
    Part of #8764.
    
    * fix(services/ftp): ignore aborted reply for zero-length reads
    
    A zero-length range never reads the data connection. Finishing the transfer 
immediately makes the server report an aborted transfer, so ignore the 
completion reply for that case instead of turning a valid empty range into an 
error.
---
 core/Cargo.lock                 |  6 ++---
 core/services/ftp/Cargo.toml    |  2 +-
 core/services/ftp/src/reader.rs | 58 +++++++++++++++++++++++++++++++++--------
 core/services/ftp/src/writer.rs | 18 +++++--------
 4 files changed, 58 insertions(+), 26 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index 80d0373f02..419f61221c 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -12347,12 +12347,12 @@ checksum = 
"13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
 
 [[package]]
 name = "suppaftp"
-version = "10.0.2"
+version = "13.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "821001051ea3d12a60fb790b8c7cb9a6f5f8698dcfdca4cd533a025fefb0b5b8"
+checksum = "919688e3d2128f0c3e77f4dff7a2035f2d73ccf488851ba96ba42002e850cad5"
 dependencies = [
  "async-trait",
- "chrono",
+ "jiff 1.0.1",
  "lazy-regex",
  "log",
  "pin-project",
diff --git a/core/services/ftp/Cargo.toml b/core/services/ftp/Cargo.toml
index bece9ae122..bc8003d2a9 100644
--- a/core/services/ftp/Cargo.toml
+++ b/core/services/ftp/Cargo.toml
@@ -39,7 +39,7 @@ log = { workspace = true }
 opendal-core = { path = "../../core", version = "0.59.5", default-features = 
false }
 rustls-native-certs = "0.8"
 serde = { workspace = true, features = ["derive"] }
-suppaftp = { version = "10.0.2", default-features = false, features = [
+suppaftp = { version = "13.0.0", default-features = false, features = [
   "tokio-rustls-ring",
 ] }
 tokio = { workspace = true, features = ["io-util", "macros", "time"] }
diff --git a/core/services/ftp/src/reader.rs b/core/services/ftp/src/reader.rs
index 28542272df..e22d9f1573 100644
--- a/core/services/ftp/src/reader.rs
+++ b/core/services/ftp/src/reader.rs
@@ -28,15 +28,20 @@ use opendal_core::*;
 use std::sync::Arc;
 use suppaftp::FtpError;
 use suppaftp::Status;
+use suppaftp::tokio::AsyncRustlsStream;
+use suppaftp::tokio::TransferStream;
 use suppaftp::types::Response;
-use tokio::io::AsyncRead;
 use tokio::io::AsyncReadExt;
 
 pub struct FtpReadStream {
+    /// Declared before `_ftp_stream` so the data connection is always closed
+    /// before the control connection returns to the pool.
+    data_stream: Option<TransferStream<AsyncRustlsStream>>,
+
     /// Keep the connection alive while data stream is alive.
     _ftp_stream: bounded::Object<Manager>,
-
-    data_stream: Box<dyn AsyncRead + Sync + Send + Unpin + 'static>,
+    /// Bytes left in the requested range, or `u64::MAX` for an open-ended 
read.
+    remaining: u64,
     chunk: usize,
     buf: BytesMut,
 }
@@ -59,16 +64,16 @@ impl FtpReadStream {
                 .await
                 .map_err(format_ftp_error)?;
         }
-        let ds = ftp_stream
+        let data_stream = ftp_stream
             .retr_as_stream(path)
             .await
-            .map_err(format_ftp_error)?
-            .take(size as _);
+            .map_err(format_ftp_error)?;
 
         Ok(Self {
-            _ftp_stream: ftp_stream,
+            data_stream: Some(data_stream),
 
-            data_stream: Box::new(ds),
+            _ftp_stream: ftp_stream,
+            remaining: size,
             chunk: 1024 * 1024,
             buf: BytesMut::new(),
         })
@@ -77,12 +82,43 @@ impl FtpReadStream {
 
 impl oio::ReadStream for FtpReadStream {
     async fn read(&mut self) -> Result<Buffer> {
-        self.buf.resize(self.chunk, 0);
-        let n = self
-            .data_stream
+        // A zero-length range never reads from the server. Finish the
+        // transfer without checking the reply: closing the data connection
+        // early makes the server report an aborted transfer even though the
+        // requested range is complete.
+        if self.remaining == 0 {
+            if let Some(data_stream) = self.data_stream.take() {
+                let _ = data_stream.finish().await;
+            }
+            return Ok(Buffer::new());
+        }
+
+        let Some(data_stream) = self.data_stream.as_mut() else {
+            return Ok(Buffer::new());
+        };
+
+        let limit = self.remaining.min(self.chunk as u64) as usize;
+        self.buf.resize(limit, 0);
+        let n = data_stream
             .read(&mut self.buf)
             .await
             .map_err(new_std_io_error)?;
+        self.remaining -= n as u64;
+
+        if n == 0 || self.remaining == 0 {
+            let data_stream = self
+                .data_stream
+                .take()
+                .expect("ftp data stream must be initialized");
+            let result = data_stream.finish().await;
+            // A range-limited read closes the data connection before the
+            // server finishes sending, so its completion reply may report an
+            // aborted transfer even though every requested byte arrived.
+            if n == 0 {
+                result.map_err(format_ftp_error)?;
+            }
+        }
+
         Ok(Buffer::from(self.buf.split_to(n).freeze()))
     }
 }
diff --git a/core/services/ftp/src/writer.rs b/core/services/ftp/src/writer.rs
index e0be505255..7916091c13 100644
--- a/core/services/ftp/src/writer.rs
+++ b/core/services/ftp/src/writer.rs
@@ -17,7 +17,8 @@
 
 use asyncband::pool::bounded;
 use bytes::Buf;
-use tokio::io::AsyncWrite;
+use suppaftp::tokio::AsyncRustlsStream;
+use suppaftp::tokio::TransferStream;
 use tokio::io::AsyncWriteExt;
 
 use super::core::Manager;
@@ -71,7 +72,7 @@ pub struct FtpWriter {
     append: bool,
     /// Declared before `ftp_stream` so the data connection is always closed
     /// before the control connection returns to the pool.
-    data_stream: Option<Box<dyn AsyncWrite + Sync + Send + Unpin + 'static>>,
+    data_stream: Option<TransferStream<AsyncRustlsStream>>,
     ftp_stream: bounded::Object<Manager>,
     /// Bytes actually sent over the data stream.
     written: u64,
@@ -107,9 +108,7 @@ impl FtpWriter {
 
     /// Open the data stream on first use so that empty writes and appends
     /// still create the remote file once the stream is finalized.
-    async fn data_stream(
-        &mut self,
-    ) -> Result<&mut Box<dyn AsyncWrite + Sync + Send + Unpin + 'static>> {
+    async fn data_stream(&mut self) -> Result<&mut 
TransferStream<AsyncRustlsStream>> {
         if self.data_stream.is_none() {
             if !self.state.may_open_data_stream() {
                 return Err(Error::new(
@@ -119,12 +118,12 @@ impl FtpWriter {
                 .with_operation("FtpWriter::data_stream"));
             }
             let path = self.tmp_path.as_ref().unwrap_or(&self.target_path);
-            self.data_stream = Some(Box::new(
+            self.data_stream = Some(
                 self.ftp_stream
                     .append_with_stream(path)
                     .await
                     .map_err(format_ftp_error)?,
-            ));
+            );
         }
 
         Ok(self
@@ -182,10 +181,7 @@ impl oio::Write for FtpWriter {
             data_stream.flush().await.map_err(|err| {
                 Error::new(ErrorKind::Unexpected, "flush data stream 
failed").set_source(err)
             })?;
-            self.ftp_stream
-                .finalize_put_stream(data_stream)
-                .await
-                .map_err(format_ftp_error)?;
+            data_stream.finish().await.map_err(format_ftp_error)?;
             self.state = CloseState::Rename;
         }
 

Reply via email to