I'm trying to SFTP to a server using identity string: SSH-2.0-AWS_SFTP_1.0 with the following Java code using sshj.
<dependency>
<groupId>com.hierynomus</groupId>
<artifactId>sshj</artifactId>
<version>0.29.0</version>
</dependency>
private SSHClient setupSshj(String remoteHost, String username, String password) throws IOException {
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
client.connect(remoteHost);
client.authPassword(username, password);
return client;
}
public void sftpfiles() throws IOException {
if (Boolean.parseBoolean(GetConfigValue("dds", "sendFiles"))) {
SSHClient sshClient = setupSshj(GetConfigValue("dds", "RemoteAddress"), GetConfigValue("dds", "RemoteLogin"), GetConfigValue("dds", "RemotePassword"));
SFTPClient sftpClient = sshClient.newSFTPClient();
sftpClient.put("/home/vm/test.txt", GetConfigValue("dds", "RemoteDirectory"));
sftpClient.close();
sshClients.disconnect();
}
}
and get the error
Error SETSTAT unsupported
I understand that the AWS service doesn’t allow setting timestamps when uploading however I don't know what adjustments are required in order to configure the SFTP client.
It seems that sshj SSHClient
API does not allow preventing the use of the SETSTAT request. You will have to use more low level API, like SFTPFileTransfer
:
SFTPEngine engine = new SFTPEngine(sshClient).init();
SFTPFileTransfer xfer = new SFTPFileTransfer(engine);
xfer.setPreserveAttributes(false);
xfer.upload("/home/vm/test.txt", GetConfigValue("dds", "RemoteDirectory"));