Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

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/test/.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("/test/in/");  ** This line throws the exception. Please note the directories do exit and this client  works if change directories in 2 steps like ..sftpClient.cd("/test/); and  sftpClient.cd("/in/);

    Does any one have a clue about this?
    Any clue would be highly appreciated.

    Thanks in advance,
    Pravin.

     
    • Cyberdemon
      Cyberdemon
      2007-03-15

      Hi, I'd suggest you look for this problem in the j2ssh documentation - this is not related to code of this project but to the underlying j2ssh code.