I have an project where I need to fetch .csv files from Remote FTP folder the issue is that the files are big lets say 6-7 MB and the poll starts reading them even though the are not yet fully transferred from the third party, it is cause an exception.
I saw that we can use a LastModifiedFileListFilter but not sure if this is the proper solution.
Here is my code sample.
@Bean
public IntegrationFlow ftpInboundFlow() {
return IntegrationFlows
.from(Ftp.inboundAdapter(ftpSessionFactory())
.preserveTimestamp(true)
.remoteDirectory("/ftp/GE/Inbound")
.patternFilter("*.csv")
.deleteRemoteFiles(true)
.localDirectory(new File("inbound"))
.temporaryFileSuffix(TEMPORARY_FILE_SUFFIX),
e -> e.id("ftpInboundAdapter")
.poller(Pollers.fixedDelay(5000))
.autoStartup(true))
.transform(e -> {
log.info("Sending CSV file " + e + " to FTP server");
return e;
})
.handle(Ftp.outboundAdapter(ftpSessionFactory())
.useTemporaryFileName(true)
.autoCreateDirectory(true)
.remoteDirectory("/ftp/GE/Inbound/history"))
.get();
}
Exception:
Caused by: org.springframework.messaging.MessagingException: Failure occurred while copying '/ftp/GE/Inbound/OA_ex_PK_2020_2021.csv' from the remote to the local directory; nested exception is java.io.IOException: Failed to copy '/ftp/GE/Inbound/OA_ex_PK_2020_2021.csv'. Server replied with: 550 The process cannot access the file because it is being used by another process.