punitpawar has asked for the wisdom of the Perl Monks concerning the following question:

So I want to connect to a SFTP server using a ppk file that is provided to me. I am able to establish the SFTP connection to this server using a client like FileZilla and using an utility like Pageant ( to upload the PPK file ). However I am not able to achieve this task of connecting to the server via Perl. Please find my code snippet below which I am using to establish the connection
use Net::SFTP; use Net::SSH::Perl::Auth; #!/usr/bin/perl $ENV{HOME} = "C:\\Perl\\myscripts\\etc"; my $host = 'test.secure01.batch.netgiro.com'; my %args = ( user => 'vistaprint_test', ssh_args => { identity_files => ["/home/ssh/id_rsa"], protocol=>'2,1', debug=>'true'} ); my $sftp = Net::SFTP->new($host, %args); print "connected!";
-------------------------------- SO for my ssh_args hash above, I am not sure what value should I include for the key 'Identity_files' I tried to point it to the PPK file which I have with me...but it did not help at all.... I get the following output
DEVPPAWAR: Reading configuration data C:\Perl\myscripts\etc/.ssh/confi +g DEVPPAWAR: Reading configuration data /etc/ssh_config DEVPPAWAR: Connecting to test.secure01.batch.netgiro.com, port 22. DEVPPAWAR: Remote protocol version 2.0, remote software version OpenSS +H_4.3 DEVPPAWAR: Net::SSH::Perl Version 1.34, protocol version 2.0. DEVPPAWAR: No compat match: OpenSSH_4.3. DEVPPAWAR: Connection established. DEVPPAWAR: Sent key-exchange init (KEXINIT), wait response. DEVPPAWAR: Algorithms, c->s: 3des-cbc hmac-sha1 none DEVPPAWAR: Algorithms, s->c: 3des-cbc hmac-sha1 none DEVPPAWAR: Entering Diffie-Hellman Group 1 key exchange. DEVPPAWAR: Sent DH public key, waiting for reply. DEVPPAWAR: Received host key, type 'ssh-dss'. DEVPPAWAR: Host 'test.secure01.batch.netgiro.com' is known and matches + the host key. DEVPPAWAR: Computing shared secret key. DEVPPAWAR: Verifying server signature. DEVPPAWAR: Waiting for NEWKEYS message. DEVPPAWAR: Send NEWKEYS. DEVPPAWAR: Enabling encryption/MAC/compression. DEVPPAWAR: Sending request for user-authentication service. DEVPPAWAR: Service accepted: ssh-userauth. DEVPPAWAR: Trying empty user-authentication request. DEVPPAWAR: Authentication methods that can continue: publickey,gssapi- +with-mic,p assword. DEVPPAWAR: Next method to try is publickey. DEVPPAWAR: Next method to try is password. DEVPPAWAR: Trying password authentication. DEVPPAWAR: Will not query passphrase in batch mode. DEVPPAWAR: Authentication methods that can continue: publickey,gssapi- +with-mic,password. . . . DEVPPAWAR: Next method to try is publickey. DEVPPAWAR: Next method to try is password. Permission denied at C:/strawberry/perl/site/lib/Net/SFTP.pm line 62
Any help on this would be highly appreciated....I am on a Windows machine . Please let me know if any more info is needed .... Thanks a lot for the help !!!

Replies are listed 'Best First'.
Re: How to establish SFTP connection to a server using a ppk file
by thewebsi (Scribe) on Jul 20, 2012 at 06:27 UTC

    Mostly responding because no one else has... PPK is a file format used by PuTTY (which Pageant is part of), and not really by any other software. The SSH (.pub) open standard is much more common, and supported by Net::SFTP. You can use PuTTYGen to export to the OpenSSH format, and use that instead.

      HI Arnon, Thanks for the reply.So the ppk file which I am currently using to load via Pagent has the following content :
      PuTTY-User-Key-File-2: ssh-rsa Encryption: none Comment: imported-openssh-key Public-Lines: 4 AAAAB3NzaC1yc2EAAAABIwAAAIEAlZaCpbUY1cVpO3D8i74QA0PnlExO2hOpS+mh ...bl +a bla bla Private-Lines: 8 AAAAgDNJi+EK4/GFgypSn7riFB5gbKffpgGgV006KOcQnKv2d3G2mRUaT5zHkk08 ...bl +a bla bla Private-MAC: 21d2a17d1378533ce907f67ca647f217ab35c548
      So by just looking at the file I guess it includes the publi c and private key which it uses to connect to the SFTP server. I tried to export the OPen SSH format as you mentioned earlier via puttygen for this file and saved the file as "Identity" . But not sure if there is a need for me to load the same file twice and save it once as Private Key and then for Public key.....PLease correct me If I am wrong here...This is only because I have one file which I assume has public and private key both in it.....(coz th eppk file says "public lines ....Private lines" Also what would be the arguments that I would need to given in my hash (ssh_args) for identity files ? Do the Identity files point to the public or private key location folder ? Currently by default it generates a file known as "Known_hosts2" in my home directory... IF you could give me some guidance on this that would be great... Thanks again for your time and help !!

        This is stepping outside the realm of Perl now, and is more of an SSH question. Typically the client only needs one file - the private key / identity - which is installed locally, and would be referred to by your Net::SFTP call (in identity_files). The public key is installed on the server-side, which I assume is already done if you connected successfully via FileZilla.

        The known_hosts file is something else, not really related to this. You might want to spend a few minutes reading up about SSH to learn more.