This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 6d02a98d852 CAMEL-22262: camel-ftp - Fix getRelativeFilePath for (S)FTP with null relativePath (#18687) 6d02a98d852 is described below commit 6d02a98d85234377c5bd0325c715d6e708583aa5 Author: Benjamin Graf <gra...@users.noreply.github.com> AuthorDate: Wed Jul 23 14:11:27 2025 +0200 CAMEL-22262: camel-ftp - Fix getRelativeFilePath for (S)FTP with null relativePath (#18687) --- .../camel/component/file/remote/FtpConsumer.java | 2 +- .../camel/component/file/remote/SftpConsumer.java | 2 +- .../SftpSimpleConsumeWithAntIncludeIT.java | 31 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java index 3d0a222a6fb..7811baa33f9 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java @@ -321,7 +321,7 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> { // the relative filename, skip the leading endpoint configured path String relativePath = StringHelper.after(absolutePath, endpointPath); // skip leading / - return FileUtil.stripLeadingSeparator(relativePath + "/") + file.getName(); + return FileUtil.stripLeadingSeparator(relativePath != null ? relativePath + "/" : "") + file.getName(); }; } diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java index 83b6ec6e8a1..32e7011cbb4 100644 --- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java +++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java @@ -274,7 +274,7 @@ public class SftpConsumer extends RemoteFileConsumer<SftpRemoteFile> { return () -> { String relativePath = StringHelper.after(absolutePath, endpointPath); // skip trailing / - return FileUtil.stripLeadingSeparator(relativePath + "/") + file.getFilename(); + return FileUtil.stripLeadingSeparator(relativePath != null ? relativePath + "/" : "") + file.getFilename(); }; } diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeWithAntIncludeIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeWithAntIncludeIT.java index a95e9924093..1e2219a2a33 100644 --- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeWithAntIncludeIT.java +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpSimpleConsumeWithAntIncludeIT.java @@ -62,6 +62,37 @@ public class SftpSimpleConsumeWithAntIncludeIT extends SftpServerTestSupport { } } + @Test + public void testSftpSimpleConsumeWithTrailingSlash() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("sftp://localhost:{{ftp.server.port}}/{{ftp.root.dir}}/" + + "?username=admin&password=admin&delay=10000&disconnect=true" + + "&recursive=true&antInclude=hello.txt" + + "&knownHostsFile=" + + service.getKnownHostsFile()).to("mock:result"); + } + }); + context.start(); + + try { + String expected = "Hello World"; + + // create file using regular file + template.sendBodyAndHeader("file://" + service.getFtpRootDir(), expected, Exchange.FILE_NAME, "hello.txt"); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt"); + mock.expectedBodiesReceived(expected); + + MockEndpoint.assertIsSatisfied(context); + } finally { + context.stop(); + } + } + @Test public void testSftpSimpleConsumeWithSubdir() throws Exception { context.addRoutes(new RouteBuilder() {