diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java index 0c285ee109..285740e664 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java @@ -505,7 +505,10 @@ public abstract class AbstractInboundFileSynchronizer try { String remoteFileMetadata = new URI(protocol(), null, host, Integer.parseInt(port), - '/' + remoteDirectoryPath, null, remoteFileName) + remoteDirectoryPath.charAt(0) == '/' + ? remoteDirectoryPath : + '/' + remoteDirectoryPath, + null, remoteFileName) .toString(); this.remoteFileMetadataStore.put(buildMetadataKey(localFile), remoteFileMetadata); } diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java index 9828fe7ad4..d39d147971 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java @@ -75,7 +75,7 @@ public class SftpTests extends SftpTestSupport { IntegrationFlow flow = IntegrationFlow .from(Sftp.inboundAdapter(sessionFactory()) .preserveTimestamp(true) - .remoteDirectory("sftpSource") + .remoteDirectory("/sftpSource") .regexFilter(".*\\.txt$") .localFilenameExpression("#this.toUpperCase() + '.a'") .localDirectory(getTargetLocalDirectory()) @@ -91,6 +91,7 @@ public class SftpTests extends SftpTestSupport { File file = (File) payload; assertThat(file.getName()).isEqualTo(" SFTPSOURCE1.TXT.a"); assertThat(file.getAbsolutePath()).contains("localTarget"); + assertThat(message.getHeaders()).containsEntry(FileHeaders.REMOTE_DIRECTORY, "/sftpSource"); message = out.receive(10_000); assertThat(message).isNotNull();