Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Can't connect using Password with Net::SFTP::Foreign

by coglesby (Initiate)
on Apr 30, 2009 at 20:44 UTC ( #761163=perlquestion: print w/replies, xml ) Need Help??
coglesby has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have been tasked with a project that requires me to utilize a PERL script to login to an SFTP server to retrieve files. When using standard FTP, this works perfect but this requires SFTP and there-in lies my problem. I turned on debugging mode and here is the result from trying to execute:
# queueing msg len: 5, code:1, id:3 ... [1] 00 00 00 05 01 00 00 00 03 + | ......... # waiting for message... [1] connection failed: bad remote message received
I read everything I could find on here pertaining to this problem but can't find what I'm looking for so any help is appreciated! Below is the code I am trying to run:
use Net::SFTP::Foreign ; $Net::SFTP::Foreign::debug = 25; sub mget { my($mysftp) = shift; my($filename) = shift; my($remote_path) = shift ; my($local_path) = shift ; my $ls = $mysftp->ls(); chop $filename; foreach $ls (@$ls) { if ($ls->{filename} =~ m/$filename/) { $mysftp->get($ls->{filename}, $local_path . $ls->{filename}) or wa +rn $mysftp->error; } } } my($sftp) ; # sftp object variable my($myhost) ; # hostname to connect to my($myuser) ; my($mypass) ; my($myremotedir) ; my($mylocaldir) ; my($myfilename) ; my($parameterfile) ; if ($#ARGV != 0) { die "usage: $ARGV[-1] <parameter filename>\n $ARGV[0] --help + for parameter file layout\n"; } if ($ARGV[0] eq "--help") { printf "usage: $ARGV[-1] <parameter filename>\n" ; printf " parameter file layout:\n" ; printf "<host>\n" ; printf "<login>\n" ; printf "<password>\n" ; printf "<remote_path>\n" ; printf "<local_path>\n" ; printf "<filename/mask>\n\n" ; exit() ; } $parameterfile = $ARGV[0] ; open (PARMFILE, $parameterfile) || die "couldn't open parameter file $ +parameterfile!\n" ; $myhost = <PARMFILE> ; $myuser = <PARMFILE> ; $mypass = <PARMFILE> ; $myremotedir = <PARMFILE> ; $mylocaldir = <PARMFILE> ; $myfilename = <PARMFILE> ; close(PARMFILE) ; chomp($myhost); chomp($myuser); chomp($mypass); chomp($myremotedir); chomp($mylocaldir); chomp($myfilename); if (substr($mylocaldir, -1) ne "/") { $mylocaldir .= "/" ; } $sftp = Net::SFTP::Foreign->new($myhost, user => $myuser, password => +$mypass, more => '-v' ); $sftp->error and die "connection failed: " . $sftp->error(); print "sftp-status = " . $sftp->status(); mget($sftp,$myfilename,$myremotedir,$mylocaldir) ;

Replies are listed 'Best First'.
Re: Can't connect using Password with Net::SFTP::Foreign
by frieduck (Hermit) on May 01, 2009 at 01:51 UTC

    Can you connect with a command line SFTP client? This would help rule out non-Perl issues (network, server configuration, etc).

    If you're connecting to a GlobeScape server, you may be running into a bug in GlobeScape's SFTP server implementation. This bug is known to affect multiple SFTP clients.

Re: Can't connect using Password with Net::SFTP::Foreign
by salva (Abbot) on May 01, 2009 at 09:13 UTC
    Set $Net::SFTP::Foreign = -1 and post the full debugging output
      Yes I can connect directly if I remove the password parameter and keying the password at the prompt and the transfer is successful. I was pulled into another task today and was unable to test further but will add that full debug Monday morning. Thanks very much!
        The debug message is the same output:
        # queueing msg len: 5, code:1, id:3 ... [1] 00 00 00 05 01 00 00 00 03 # waiting for message... [1] connection failed: bad remote message received
        I read in another thread there was a known issue in versions previous to 1.37 of this package that the expect module suddenly would drop connections so I was suspicious of that but I don't seem to be getting that error or I'm not making it that far. It appears we are on version 1.31 so I have asked our admin's to upgrade this module to the current version to see if that helps. I apologize for my ignorance but I am relatively new to PERL so this is a big learning experience for me.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://761163]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-04-25 19:19 GMT
Find Nodes?
    Voting Booth?