I am getting below exception while connecting to SFTP server with public key.
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import com.enterprisedt.net.ftp.ssh.SSHFTPClient;
public class FtpFile {
public static void main(String[] args) {
InputStream privateKeyStream = null;
try {
File f = new File("/XX/yy/zz.asc");
privateKeyStream = new FileInputStream(f);
SSHFTPClient SFTP = new SSHFTPClient();
SFTP.setRemoteHost("XXX");
SFTP.setRemotePort(0);
SFTP.setAuthentication(privateKeyStream, "XXX", "YYYY");
SFTP.getValidator().setHostValidationEnabled(false);
SFTP.connect();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (privateKeyStream != null)
try {
privateKeyStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Exception : com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException : Can't read key due to internal IO problems:
com.enterprisedt.net.j2ssh.transport.publickey.InvalidSshKeyException: Can't read key due to internal IO problems:
at com.enterprisedt.net.j2ssh.openssh.OpenSSHPrivateKeyFormat.decryptKeyblob(Unknown Source)
at com.enterprisedt.net.j2ssh.transport.publickey.SshPrivateKeyFile.toPrivateKey(Unknown Source)
at com.enterprisedt.net.ftp.ssh.SCPClient.setAuthentication(Unknown Source)