develooper Front page | perl.beginners | Postings from March 2002

Net::FTP::Common - get(RemoteFile => ?)

Thread Next
From:
Brian Volk
Date:
March 21, 2002 12:00
Subject:
Net::FTP::Common - get(RemoteFile => ?)
Message ID:
3C9A3C2A.6080604@bvolk.com
Hi All,

I'm trying to have perl get a file from my web hosting account.  I 
searched around and found Net::FTP::Common.  I get logged into my ftp 
account and can perform a "ls" but I get an error when I try to get a 
file.  Here's the error:  

Net::FTP=GLOB(0x82fc210)<<< 230 User bvolk logged in.
Net::FTP=GLOB(0x82fc210)>>> CWD /web
Net::FTP=GLOB(0x82fc210)<<< 250 CWD command successful.
Net::FTP=GLOB(0x82fc210)>>> TYPE A
Net::FTP=GLOB(0x82fc210)<<< 200 Type set to A.
Net::FTP=GLOB(0x82fc210)>>> PORT 64,1,0,200,5,34
Net::FTP=GLOB(0x82fc210)<<< 200 PORT command successful.
Net::FTP=GLOB(0x82fc210)>>> RETR
Net::FTP=GLOB(0x82fc210)<<< 500 'RETR ': command not understood.
download of  to get_test.txt failed at 
/usr/lib/perl5/site_perl/5.6.0/Net/FTP/Common.pm line 243.

Notice how it says download of (blank) to get_test.txt  could this be 
something?

-------------  part of Common.pm (line 243) -----------------
sub get {

  my ($self,%cfg) = @_;

  my $ftp = $self->prep(%cfg);

  my $r;

  my $file = $self->GetCommon('LocalFile')
      ? $self->GetCommon('LocalFile') : $self->GetCommon('File') ;
  my $local_file = join '/', ($self->GetCommon('LocalDir'), $file);
       

  if ($r = $ftp->get($self->GetCommon('File'), $local_file)) {
      return $r;
  } else {
    warn sprintf "download of %s to %s failed",     <-----------  LINE 243
      $self->GetCommon('File'), $self->GetCommon('LocalFile');
    return undef;
}

----------------and now for the perl script :-) 
-------------------------------

Looks like everything is working except for the last line.

Thanks for your help!!!  

Brian Volk
bvolk@bvolk.com

PS:  I'm new to perl, so go easy...  :-)
----------------------------------------------------------------------

#!/usr/bin/perl

use Net::FTP::Common;

     our %netftp_cfg =
        (Debug => 1, Timeout => 120);

     our %common_cfg =    
        (
         #
         # The first 2 options, if not present,
         # lead to relying on .netrc for login
         #
         User => 'username',           
         Pass => 'password',      

         #
         # Other options
         #

         LocalDir  => '/home/bvolk/perl',   # setup something for $ez->get
         LocalFile => 'get_test.txt',       # setup something for $ez->get
         Host => 'ftp.somewhere.com',          # ftp site
         RemoteDir  => '/web',                    # automatic CD on 
remote machine to RemoteDir
         RemoteFile => '/web/get_text.txt',
         Type => 'A'                     # overwrite I (binary) TYPE default
         );

      $ez = Net::FTP::Common->new(\%common_cfg, %netftp_config);

      # can we login to the machine?
    
      $ez->login or die "cant login: $@";

      # Get a listing of a remote directory
 
      @listing =    $ez->ls;    
      
      # Get a file from the remote machine, specifying dir:

      $ez->get(RemoteFile => 'get_text.txt', LocalDir => '/home/bvolk', 
LocalFile => 'get_test.txt');   


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About