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

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

Hello Kind and Wise Monks:

I have some scripts working which download files off a FTP site. Given that these scripts are working the site is being upgraded to SFTP. Happy Happy.

I am attempting to use Net::SFTP to do these simple down loads. I can retieve he files using Filezilla, so I know I have the correct logon info.

Please take a look at the following code
use Net::SFTP; $SFTPSite = 'sftp.xxxxbroker' ; $userid = 'fred'; $pword = 'bedrock'; #** ** ** ** ** ** ** ** # Setup to do the SFTP $sftp = Net::SFTP->new( $SFTPSite, $userid, $pword ) or die "Could NOT create SFTP " ; #Net::SFTP const +ructor @entries = $sftp->ls('/'); # slurp all entries into an array foreach $entry (@entries) { print "$entry \n"; chomp $entry; my @fields = split /\s+/, $entry; print "the file name: " . $fields[-1] . "\n"; }

When run, this code produces the following error:
Name "main::pword" used only once: possible typo at testSFTP.pl line 9 +. Name "main::userid" used only once: possible typo at testSFTP.pl line +8. The getpwuid function is unimplemented at c:/progFiles/PERL/site/lib/N +et/SSH/Per l.pm line 110.
The last message is the one I do not know what to do with.
I am using Active Perl 5.8.8 and I downloaded the Net::SFTP package from TheoryX5 Win32 PPM packages. I am running under windows 2000

many thanks for your help

kd

Replies are listed 'Best First'.
Re: help with Net::SFTP
by andyford (Curate) on Jan 15, 2008 at 17:51 UTC

    First point: your code and errors don't match up. The "used only once" errors indicate that you are using "use strict", but your posted code doesn't show that.

    To get help effectively, there can be no mismatch between your code and the errors!

    Here's what you need to do: use "my" to fix your errors, don't drop "use strict", for example:

    use strict; use warnings; use Net::SFTP; my $SFTPSite = 'sftp.xxxxbroker' ; my $userid = 'fred'; my $pword = 'bedrock'; #** ** ** ** ** ** ** ** # Setup to do the SFTP my $sftp = Net::SFTP->new( $SFTPSite, $userid, $pword ) or die "Could NOT create SFTP " ; #Net::SFTP const +ructor my @entries = $sftp->ls('/'); # slurp all entries into an array foreach $entry (@entries) { print "$entry \n"; chomp $entry; my @fields = split /\s+/, $entry; print "the file name: " . $fields[-1] . "\n"; }

    Then post your complete code, preferably boiled down to the smallest working portion that demonstrates your problem.

      I made the changes as you suggested, the new code follows:

      use strict; use warnings; use Net::SFTP; my $SFTPSite = 'sftp.xxxxbroker' ; my $userid = 'fred'; my $pword = 'bedrock'; my $entry = undef; #** ** ** ** ** ** ** ** # Setup to do the SFTP my $sftp = Net::SFTP->new( $SFTPSite, $userid, $pword ) or die "Could NOT create SFTP " ; #Net::SFTP const +ructor my @entries = $sftp->ls('/'); # slurp all entries into an array foreach $entry (@entries) { print "$entry \n"; chomp $entry; my @fields = split /\s+/, $entry; print "the file name: " . $fields[-1] . "\n"; }


      the following error message resulted from the above code.

      C:\dev\FTPPerl>perl testSFTP.pl The getpwuid function is unimplemented at c:/progFiles/PERL/site/lib/Net/SSH/Perl.pm line 110.

      I belive that I an missing something to support Net::SFTP. Maybe I have an old version of Net:SSH But do not know how to figure that out.
      As per the ActiveState Perl Package Manager I have the following SSH stuff installed:
      Net-SSH 0.08
      Net-SSH-Perl 1.30
      Net-SSH-W32-Perl .05

      thanks for your assistance.

      kd

        Looks like a deficiency in the Net::SSH::Perl or Net::SSH::W32Perl modules rather than a missing module. getpwuid doesn't exist on Win32, but Net::SSH::Perl is trying to call it.

        I wonder if Net::SSH::W32Perl is supposed to be some kind of helper to get around that.

        Perhaps try the example in the Net::SSH::W32Perl to see if it works by itself?

        Or take the easy-ugly-fast way and use system to shell out to a command line sftp client.