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

Hi Monks, I am new to perlmonks. I have a problem with Net::sftp module. I need to transfer files regularly between two servers using Sftp and I am using Net::Sftp module in my code.I wrote a small script to test the system :-
########################################## #!/usr/local/bin/perl use Net::SSH::Perl; use strict; my $host = "***********"; print $ENV{"HOME"}."\n"; my %params=( identity_files =>["/home/vendor2/.ssh/id_dsa"],protocol=> +'2',debug => 1); my $ssh = Net::SSH::Perl->new($host,%params); $ssh->login("vendor1") ; my $cmd = "ls -ltr "; my ($stdout) = $ssh->cmd($cmd); print $stdout; ##########################################
The Error which I am geting is --
Myserver: Reading configuration data /home/hygtest/.ssh/config Myserver: Reading configuration data /etc/ssh_config Myserver: Connecting to **********, port 22. Myserver: Remote protocol version 1.99, remote software version OpenSS +H_3.8.1p1 Myserver: Net::SSH::Perl Version 1.28, protocol version 2.0. Myserver: No compat match: OpenSSH_3.8.1p1. Myserver: Connection established. Myserver: Sent key-exchange init (KEXINIT), wait response. Myserver: Algorithms, c->s: 3des-cbc hmac-sha1 none Myserver: Algorithms, s->c: 3des-cbc hmac-sha1 none Myserver: Entering Diffie-Hellman Group 1 key exchange. Myserver: Sent DH public key, waiting for reply. Myserver: Received host key, type 'ssh-dss'. Myserver: Permanently added '*********' to the list of known hosts. Myserver: Computing shared secret key. Myserver: Verifying server signature. Key verification failed for server host key at /usr/opt/perl5/lib64/si +te_perl/5.8.0/Net/SSH/Perl/SSH2.pm line 87 #######################################
If i manually do sftp from command line from Vendor2 to Vendor1, I easily pass thru to vendor1..
Kindly suggest some solution. I have gone through earlier postings but was not able to find similar kind of error.

Thanx in advance,
Zoop
'When You starve With A Tiger, The Tiger always starves last'

Replies are listed 'Best First'.
Re: Net::SFTP Problem
by salva (Canon) on Jun 07, 2005 at 10:15 UTC
    You should try Net::SFTP::Foreign. It's a fork of Net::SFTP that uses the native ssh binary to stablish the connection with the remote host instead of Net::SSH::Perl.
      Hi Salva,

      I tried Net::SFTP::Foreign Modeule in my program. in this case I am using this code...
      ############################## #! usr/bin/perl use Net::SFTP::Foreign; $host="myserver"; $username="vendor1"; $portnumber=22; %args={port => $portnumber ,host =>$host ,user => $username ,debug => +1}; my $sftp = Net::SFTP::Foreign->new($host,%args); @str=$sftp->ls("/home/vendor1/"); foreach $hashref(@str) { foreach $key(keys%$hashref) { print "\t $$hashref{$key}\t"; } print "\n"; } #########################
      Now as both vendor1 and vendor2 are users on the same server which i dont think makes any difference,but now I am getting password prompt for vendor2...

      + perl sftp.pl vendor2@9.182.244.13's password:
      ...which i think i should not get. The output should be the output of "ls" command..
      can you suggest some solution...
      Thanx
      Zoop

      'When You starve With A Tiger, The Tiger always starves last'
        oh, I thought you were using ssh keys for authentication instead of the login and clear password aproach not supported by that Net::SFTP::Foreign.

        Is there any reason why you are not using public keys for authentication?