This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new 021c1ddea71 CAMEL-22262: camel-ftp - Fix getRelativeFilePath for
(S)FTP with null relativePath (#18687)
021c1ddea71 is described below
commit 021c1ddea71d2de1a8d22db4267c8480324af6f8
Author: Benjamin Graf <[email protected]>
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 23cfa0078aa..feee97d331a 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
@@ -316,7 +316,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 45724081576..697e5b15265 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
@@ -272,7 +272,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() {