I am using sftp outbound adaptor to transfer files generated in ItemWriter to sftp server successfully.
Following is the java dsl config for my sftp outbound gateway.
@Bean public IntegrationFlow sftpOutboundFlow() {
return IntegrationFlows.from("toSftpChannel")
.handle(Sftp.outboundAdapter(delegatingSessionFactory(sessionFactoryLocator), FileExistsMode.REPLACE)
.useTemporaryFileName(false)
.fileNameExpression("headers['" + FileHeaders.FILENAME + "']")
.remoteDirectoryExpression("headers.path")
.autoCreateDirectory(true),
c -> c.advice(expressionAdvice(c))) .get();
}
/**
* Advice to remove local files after successful upload
*
* @param c
* @return
*/
@Bean
public Advice expressionAdvice(GenericEndpointSpec<FileTransferringMessageHandler<ChannelSftp.LsEntry>> c) {
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setOnSuccessExpressionString("payload.delete()");
advice.setOnFailureExpressionString("payload + ' failed to upload'");
advice.setTrapException(true);
return advice;
}
/**
* Channel for uploading files
*
*
*/
@MessagingGateway
public interface LettersUploadGateway {
@Gateway(requestChannel = "toSftpChannel")
void upload(@Payload File file, @Header("path") String path);
}
Update: From ItemWriter I am calling gateway's upload method to transfer files as below:
lettersGateway.upload(fileName, batchConfiguration.getLettersDirectory());
The directory specified is remote directory where I want the files to be transfered.
In this process, I have noticed that the temporary local files are created in my project root folder (which are deleted later after successful sftp transfer), is there a way to change the local temporary file location to somewhere like "c:/temp/"?
Thanks for your help.