Skip to content

Commit 882685d

Browse files
artembilanspring-builds
authored andcommitted
GH-9129: SFTP: Remove extra / for the file_remoteDirectory header
Fixes: #9129 If `.remoteDirectory("/sftpSource")`, then `FileHeaders.REMOTE_DIRECTORY` is `//sftpSource` * Fix `AbstractInboundFileSynchronizer` to not add `/` if one is already present in the beginning of the `remoteDirectoryPath` (cherry picked from commit d87a709)
1 parent 67ac3c2 commit 882685d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,10 @@ protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, // NOSONA
505505
try {
506506
String remoteFileMetadata =
507507
new URI(protocol(), null, host, Integer.parseInt(port),
508-
'/' + remoteDirectoryPath, null, remoteFileName)
508+
remoteDirectoryPath.charAt(0) == '/'
509+
? remoteDirectoryPath :
510+
'/' + remoteDirectoryPath,
511+
null, remoteFileName)
509512
.toString();
510513
this.remoteFileMetadataStore.put(buildMetadataKey(localFile), remoteFileMetadata);
511514
}

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testSftpInboundFlow() {
7575
IntegrationFlow flow = IntegrationFlow
7676
.from(Sftp.inboundAdapter(sessionFactory())
7777
.preserveTimestamp(true)
78-
.remoteDirectory("sftpSource")
78+
.remoteDirectory("/sftpSource")
7979
.regexFilter(".*\\.txt$")
8080
.localFilenameExpression("#this.toUpperCase() + '.a'")
8181
.localDirectory(getTargetLocalDirectory())
@@ -91,6 +91,7 @@ public void testSftpInboundFlow() {
9191
File file = (File) payload;
9292
assertThat(file.getName()).isEqualTo(" SFTPSOURCE1.TXT.a");
9393
assertThat(file.getAbsolutePath()).contains("localTarget");
94+
assertThat(message.getHeaders()).containsEntry(FileHeaders.REMOTE_DIRECTORY, "/sftpSource");
9495

9596
message = out.receive(10_000);
9697
assertThat(message).isNotNull();

0 commit comments

Comments
 (0)