Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workaround for unsupported SETSTAT request on SFTP server with sshj

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.

like image 367
conteh Avatar asked Sep 05 '25 02:09

conteh


1 Answers

SSHJ does support skipping SETSTAT method.

sftpClient.getFileTransfer().setPreserveAttributes(false)
like image 137
MrAaronOlsen Avatar answered Sep 06 '25 18:09

MrAaronOlsen