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) ;

In reply to Can't connect using Password with Net::SFTP::Foreign by coglesby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.