http://www.perlmonks.org?node_id=967629

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

I've been using Net::SFTP::Foreign with the Net_SSH2 backend for username/password and private key authentication without error for a little while now but I've been recently tasked with adding in functionality to utilize passphrase protected private keys.

Net:SFTP::Foreign has an option for passphrase, according to CPAN, but when utilizing it I get the error "Invalid option 'passphrase' or bad combination of options at sftpTest.pl line 15".

It seems that Net::SFTP::Foreign passes the SFTP object's arguments directly to the Net_SSH2 backend and passphrase is not a recognized argument for the Net_SSH2 backend. Is that correct or am I way off base? If that is correct, is there a way to utilize passphrase protected private keys in Perl?

Below is my test script. Also, this has to be platform independent so utilizing the always useful linux command line arguments isn't an option. Thanks for any help.

use Net::SFTP::Foreign; my $host = 'localhost'; my $user = 'sshuser'; my $privateKey = "C:\\id_rsa"; my $file = "C:\\sshuser-results.xml"; my $passphrase = "password"; my $sftp = Net::SFTP::Foreign-> new(host => $host, backend => 'Net_SSH2', user => $user, key_path => $privateKey, passphrase => $passphrase, ); if( not $sftp) { $sftp->die_on_error("Unable to establish SFTP connection"); } elsif($sftp->error) { $sftp->die_on_error("Connect Failed: " .$sftp->status); } else { print "Connected!\n"; if($sftp->get("sshTest.txt")) { print "get success: " . $sftp->status . "\n"; } else{ print "get failed: " . $sftp->error . "\n"; } if($sftp->put($file)){ print "put file success \n"; } else{ print "put failed: " . $sftp->error . "\n"; } }