0

自宅の別のラップトップで実行されている(win 10で実行されている)SFTPサーバーに接続しようとしています。SSHJライブラリを使用しています。パスワードによる認証を使用すると、正常に動作します。

client.authPassword("myUserName", "myPassword") 

しかし、キーを使用して認証しようとすると、「使用可能な認証方法が使い果たされました」という例外が発生します。秘密キーと公開キーのどちらを使用する必要があるかわからなかったので、両方を試しました (SFTP サーバーから取得)。同じエラー。これが私のコードです:

public static void sftpUsingKey() throws IOException {
    final SSHClient client = new SSHClient();
    client.loadKnownHosts();
    try {
        client.addHostKeyVerifier(new PromiscuousVerifier());
        client.connect(remoteHost);
        PKCS8KeyFile keyfile = new PKCS8KeyFile();
        File privateKeyFile = new File("path/to/key");
        keyfile.init(privateKeyFile);
        client.authPublickey("myUserName", keyfile);

        final SFTPClient sftp = client.newSFTPClient();
        try {
            sftp.put(new FileSystemFile(src+fileName), remoteDst);
        }
        catch (Exception e){
            System.out.println(e.getMessage());
        }
        finally {
            sftp.close();
        }
    }
    catch(Exception e){
        System.out.println(e.getMessage());
    } finally {
        client.disconnect();
    }
}

私が間違っていることは何ですか?

4

0 に答える 0