How can i get response if file is uploaded succesfuly to sftp? This is the code which i have
@Bean
public SessionFactory<LsEntry> axisSftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(axisSftpProperties.getSftpHost());
factory.setPort(axisSftpProperties.getSftpPort());
factory.setUser(axisSftpProperties.getSftpUser());
factory.setPassword(axisSftpProperties.getSftpPassword());
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<>(factory);
}
/**
* Handler message handler.
*
* @return the message handler
*/
@Bean
@ServiceActivator(inputChannel = TO_SFTP_CHANNEL)
public MessageHandler handler() {
SftpMessageHandler handler = new SftpMessageHandler(axisSftpSessionFactory());
handler.setRemoteDirectoryExpression(new LiteralExpression(axisSftpProperties.getSftpRemoteDirectory()));
handler.setFileNameGenerator(message -> (String) message.getHeaders().get(FILENAME));
return handler;
}
@Component
@MessagingGateway
public interface UploadGateway {
@Gateway(requestChannel = TO_SFTP_CHANNEL)
String upload(@Header(FILENAME) String filename, @Payload byte[] bytes);
}
And the idea here is to catch any error if the file is not successfully uploaded to sftp to be able to retry it.
If i use SftpOutboundGateway how can setup a remote directory path? SftpOutboundGateway gateway = new SftpOutboundGateway(sessionFactory(), "put", "payload");