I am trying to sft file to mainframe using spring integration sftp:outbound-gateway: this is configuration:
To follow up on what Artem pointed out, when sFTPing to, for example, a cloud Axway sFTP server, where I was told that the current working directory was "/"
First, I used a terminal sftp client:
$ sftp username@mft-xxx.axwaycloud.com
sftp> pwd
Remote working directory: /
This isn't the root /, but the chrooted directory so that I have no way to determine what the absolute path is. The below code String ftpRemoteDestinationPath = "/" + tempFile.getName(); works though in this situation:
if (tempFile.exists()) {
try {
axwaySftpRemoteFileTemplate.execute((SessionCallback) session -> {
String ftpRemoteDestinationPath = "/" + tempFile.getName();
logger.info("FTP local file residing on server: [" + tempFile.getAbsolutePath() + "]");
InputStream targetStream = new FileInputStream(tempFile);
logger.debug("sftp uploading file: [" + tempFile.getName() + "] using channel connected to an sftp server :[" + session.getClientInstance().toString() + "]");
session.write(targetStream, ftpRemoteDestinationPath);
return null;
});
} catch (Exception e) {
logger.error("Could not send file per SFTP: " + e);
throw new SomeRuntimeSftpException("Error FTPing file " + tempFile.getAbsolutePath() + " " + e.getMessage());
}
finally {
tempFile.delete();
}
}