SFTP Public Key Authentication -

Help
Pravin L
2007-01-03
2013-02-24
  • Pravin L
    Pravin L
    2007-01-03

    Hi,

    I'm trying out the SFPT Public Key Authentication Client. The client works fine, but for some reason it seems to be failing on changing directories. The SFTP password client works fine for changing directories.

    Here is my code snippet

                     File privateKey =  new File("/opt/local/pegasus/.ssh/id_rsa");
                    SftpSubsystemClient sftp = null;

                    SshConnectionProperties properties = new SshConnectionProperties();
                    properties.setHost(ftpHostname);

                    SshClient ssh = new SshClient();

                    ssh.connect(properties, new IgnoreHostKeyVerification());

                    PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();
                    pk.setUsername(ftpUsername);

                    SshPrivateKeyFile file = SshPrivateKeyFile.parse(privateKey);
                    SshPrivateKey key = file.toPrivateKey(ftpPassword);

                    pk.setKey(key);
                    int result = ssh.authenticate(pk);

                    SftpClient sftpClient = ssh.openSftpClient();
    sftpClient.cd