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

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/dev/pr-13112-d1e1d79b9e09bf61ad57878b9887c7d173471f39
in repository https://gitbox.apache.org/repos/asf/seatunnel.git

commit 5bb708df7316a84bca2aca2e2a2d1ed7df9f02a2
Author: ZIHAN DAI <[email protected]>
AuthorDate: Sat Nov 21 02:05:31 2026 +0000

    [Fix][Connector-V2][FTP] Remove the active mode probe directory after each 
connection (#13112)
---
 .../file/ftp/system/SeaTunnelFTPFileSystem.java    | 14 +++++++++-----
 .../ftp/system/SeaTunnelFTPFileSystemTest.java     | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git 
a/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java
 
b/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java
index f7070a6c02..abeb4d3174 100644
--- 
a/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java
+++ 
b/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystem.java
@@ -255,10 +255,11 @@ public class SeaTunnelFTPFileSystem extends FileSystem 
implements StreamingFileS
             case ACTIVE_LOCAL:
                 // Create a test directory to check if active mode is working
                 String pathName = "/.ftptest" + System.currentTimeMillis();
+                boolean created = false;
                 try {
                     client.enterLocalActiveMode();
                     // test active mode is working or not
-                    boolean created = client.makeDirectory(pathName);
+                    created = client.makeDirectory(pathName);
                     if (!created) {
                         LOG.warn("Active mode failed, switching to passive 
mode");
                         throw new IOException("FTP connection active mode test 
failed");
@@ -272,10 +273,13 @@ public class SeaTunnelFTPFileSystem extends FileSystem 
implements StreamingFileS
                     getConf()
                             .set(FS_FTP_CONNECTION_MODE, 
FtpConnectionMode.PASSIVE_LOCAL.getMode());
                 } finally {
-                    // delete the test directory if it was created
-                    FTPFile[] files = client.listFiles(pathName);
-                    if (files != null && files.length > 0) {
-                        client.deleteFile(pathName);
+                    // remove the test directory again, otherwise every 
connection leaves an
+                    // empty directory behind on the server
+                    if (created && !client.removeDirectory(pathName)) {
+                        LOG.warn(
+                                String.format(
+                                        "Failed to remove FTP test directory 
%s, reply: %s",
+                                        pathName, 
client.getReplyString().trim()));
                     }
                 }
                 break;
diff --git 
a/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/test/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystemTest.java
 
b/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/test/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystemTest.java
index 1169f1c40e..fd17750d9e 100644
--- 
a/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/test/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystemTest.java
+++ 
b/seatunnel-connectors-v2/connector-file/connector-file-ftp/src/test/java/org/apache/seatunnel/connectors/seatunnel/file/ftp/system/SeaTunnelFTPFileSystemTest.java
@@ -49,6 +49,7 @@ import java.util.List;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -259,6 +260,27 @@ public class SeaTunnelFTPFileSystemTest {
         assertTrue(ftpFileSystem.mkdirs(testFile2.getParent(), null));
     }
 
+    @Test
+    public void testActiveModeProbeDoesNotLeaveDirectoryOnServer() throws 
IOException {
+        // No connection mode is configured, so every connection runs the 
active_local probe.
+        assertTrue(ftpFileSystem.exists(new Path(HOME_DIR + "/test.txt")));
+        assertEquals(1, ftpFileSystem.listStatus(new Path(HOME_DIR)).length);
+
+        // The probe directory could be created, so the client stayed in 
active mode.
+        assertNotEquals(
+                FtpConnectionMode.PASSIVE_LOCAL.getMode(),
+                
ftpFileSystem.getConf().get(SeaTunnelFTPFileSystem.FS_FTP_CONNECTION_MODE));
+        List<String> probeDirectories = new ArrayList<>();
+        for (Object name : fakeFtpServer.getFileSystem().listNames("/")) {
+            if (name.toString().startsWith(".ftptest")) {
+                probeDirectories.add(name.toString());
+            }
+        }
+        assertTrue(
+                probeDirectories.isEmpty(),
+                "Active mode probe left directories on the server: " + 
probeDirectories);
+    }
+
     @Test
     public void testMkdirsWithPermission() throws IOException {
         Path testDir = new Path(HOME_DIR + "/testDir/subDir");

Reply via email to