使用 sshj 在 SFTP 服务器上解决不受支持的 SETSTAT 请求的解决方法

con*_*teh 1 java sftp sshj aws-sftp

我正在尝试使用身份字符串 SFTP 到服务器:SSH-2.0-AWS_SFTP_1.0 使用 sshj 使用以下 Java 代码。

<dependency>
    <groupId>com.hierynomus</groupId>
    <artifactId>sshj</artifactId>
    <version>0.29.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
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();
    }
}
Run Code Online (Sandbox Code Playgroud)

并得到错误

错误 SETSTAT 不受支持

我知道 AWS 服务不允许在上传时设置时间戳,但是我不知道需要进行哪些调整才能配置 SFTP 客户端。

问候康泰

MrA*_*sen 6

SSHJ 确实支持跳过 SETSTAT 方法。

sftpClient.getFileTransfer().setPreserveAttributes(false)
Run Code Online (Sandbox Code Playgroud)