Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How to use identity files in Net::SFTP

by rachanakunal (Initiate)
on Oct 18, 2010 at 09:47 UTC ( [id://865909]=perlquestion: print w/replies, xml ) Need Help??

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

Hello,

I am writing a perl code to do FTP on a remote server using Net::SFTP.
For authentication, I have an identity file. But I am not clear as to how to connect through identity file. My code is:

my %args =(ssh_args => { user =>'XXXX', identity_files => [ '/home/myhome/zzz.private' ], } ); my $targetserver='file.yyy.net'; my $sftp = Net::SFTP->new($targetserver, %args) or die "could not open + connection to $targetserver\n";
When I run this code, I get an error:-
"Not an ARRAY reference at /usr/lib/perl5/site_perl/5.8.1/Net/SFTP.pm +line 36."
Please can anyone help me how to get rid of this error???

Thanks in advance!!!

Replies are listed 'Best First'.
Re: How to use identity files in Net::SFTP
by jethro (Monsignor) on Oct 18, 2010 at 11:29 UTC

    The error message you are getting suggests that Net::SFTP can't handle a hash reference. Since you have only one hash reference in your code this might be the problem.

    Quick look into the source of Net::SFTP also seems to indicate that the old Net::SFTP version 0.08 did not accept hash references for the ssh_args parameter. So either use my %args =(ssh_args => [ user =>'XXXX', identity_files =>  '/home/myhome/zzz.private'  ] );, i.e. change the {} to [], or update Net::SFTP to a newer version.

    No guarantee though, I didn't test it. If you still have problems, ask again

Re: How to use identity files in Net::SFTP
by zentara (Archbishop) on Oct 18, 2010 at 13:20 UTC
Re: How to use identity files in Net::SFTP
by rachanakunal (Initiate) on Oct 20, 2010 at 05:33 UTC
    Hello thanks for the reply.
    I have modified my code like this:
    my $targetserver = 'files.responsys.net'; my $sftp = Net::SFTP->new( $targetserver, user => 'canneu_scp', ssh_args => { identity_files => [ '/tmp/responsys/capgemini.private' ], debug => 1, } ) or die "could not open connection to $targetserver\n";
    Now when I run this, I am getting the following error:
    can-ornstein:[/tmp/responsys] ./testftp.pl can-ornstein: Reading configuration data /home/home2/cgmjoshi/.ssh/con +fig can-ornstein: Reading configuration data /etc/ssh_config can-ornstein: Connecting to files.responsys.net, port 22. can-ornstein: Remote protocol version 2.0, remote software version Ope +nSSH_5.2 can-ornstein: Net::SSH::Perl Version 1.34, protocol version 2.0. .an-ornstein: No compat match: OpenSSH_5.2 can-ornstein: Connection established. can-ornstein: Sent key-exchange init (KEXINIT), wait response. can-ornstein: Algorithms, c->s: 3des-cbc hmac-sha1 none can-ornstein: Algorithms, s->c: 3des-cbc hmac-sha1 none can-ornstein: Entering Diffie-Hellman Group 1 key exchange. can-ornstein: Sent DH public key, waiting for reply. Key class 'Net::SSH::Perl::Key::DSA' is unsupported: Math::BigInt vers +ion 1.78 required--this is only version 1.70 at /usr/lib/perl5/vendor +_perl/5.8.5/Crypt/DSA/KeyChain.pm line 4, <GEN0> line 1. BEGIN failed--compilation aborted at /usr/lib/perl5/vendor_perl/5.8.5/ +Crypt/DSA/KeyChain.pm line 4, <GEN0> line 1. Compilation failed in require at /usr/lib/perl5/vendor_perl/5.8.5/Cryp +t/DSA.pm line 7, <GEN0> line 1. BEGIN failed--compilation aborted at /usr/lib/perl5/vendor_perl/5.8.5/ +Crypt/DSA.pm line 7, <GEN0> line 1. Compilation failed in require at /usr/lib/perl5/vendor_perl/5.8.5/Net/ +SSH/Perl/Key/DSA.pm line 14, <GEN0> line 1. BEGIN failed--compilation aborted at /usr/lib/perl5/vendor_perl/5.8.5/ +Net/SSH/Perl/Key/DSA.pm line 14, <GEN0> line 1. Compilation failed in require at (eval 23) line 1, <GEN0> line 1. BEGIN failed--compilation aborted at (eval 23) line 1, <GEN0> line 1.
    The versions I am using are:
    perl-Net-SFTP-0.10-1.el4.rf perl-Net-SSH-Perl-1.34-1.el4.rf perl-Math-Pari-2.01080603-1.el4.rf perl-Math-GMP-2.05-1.el4.rf
    Can anyone help how to get rid of this error?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://865909]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found