4

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.

0

3 Answers 3

10

SSHJ does support skipping SETSTAT method.

sftpClient.getFileTransfer().setPreserveAttributes(false)
1

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"));
0
-1

By default the preserveAttributes of SFTPFileTransfer is true

 [private volatile boolean preserveAttributes = true;]

Hence, setting it to false for AWS services would stop preserving data during uploads.

1
  • 2
    Please edit your post to add code and data as text (using code formatting), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and many more reasons. Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. See minimal reproducible example on what code is required.
    – Adriaan
    Commented Oct 16, 2023 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.