I am trying to connect to SFTP server, running on another laptop at my home (running on win 10) I am using SSHJ library. When I use authentication with password, it works fine:
client.authPassword("myUserName", "myPassword")
But when I am trying to authenticate using key, I am getting exception "Exhausted available authentication methods" I wasn't sure if I need to use the private or public key, so I tried both (taken from the SFTP server), both return the same error. Here is my code:
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();
}
}
Any tip what am I doing wrong?