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

I have never managed to fetch anything with Net::FTP (I am a 3 day old CPAN newbie). I'm trying to install via the cpan command ("sudo cpan" on MacOsX Panther). Here is the the first error message:

CPAN: Net::FTP loaded ok Fetching with Net::FTP: ftp://ftp.perl.org/authors/01mailrc.txt.gz Couldn't cwd authors at /usr/local/lib/perl5/5.8.7/CPAN.pm line 2260
Here are the lines around 2260 in CPAN.pm
======code starts============= unless ( $ftp->cwd($dir) ){ warn "Couldn't cwd $dir"; return; } =======code ends==============
So, what I did was to insert an extra line into CPAN.pm, namely:
print `pwd`;

The output was '/Users/dbae/.cpan', so obviously 'authors' was not to be found. The correct directory to cwd to is sources/authors

So I've tracked down the error quite a bit, but I have no idea how to fix the error.

Any advice?

Another question: where should this question have been posted? I searched for Net::FTP on cpanforum, and got about 7 different groups, not one of which was recognizable by me.

Thanks a lot
David

Edited by Chady -- fixed formatting.

Replies are listed 'Best First'.
Re: Net::FTP is NEVER successful
by runrig (Abbot) on Jul 28, 2005 at 17:13 UTC
    When I ftp to that site, there is no authors directory in the root directory, but there is a /pub/CPAN/authors directory.
      Thanks for your reply. The error message is from CPAN.pm, one of the files on my own system. I believe that this perl program is looking for the directory "authors" in my $HOME/.cpan. In fact, the correct pathname is $HOME/.cpan/sources/authors, so it should be trying to cwd to "sources/authors". But I could be wrong about what the code means. I guess I could check it out by making a symbolic link to get round this error. But I would prefer to configure cpan correctly so it doesn't happen. David
        $ftp->cwd(...) tries to change directories on the remote system, not on the local system. To change directories on the local system, you would just use chdir.
Re: Net::FTP is NEVER successful
by socketdave (Curate) on Jul 28, 2005 at 16:33 UTC
    I'd verify that you can ftp to ftp.perl.org with a normal ftp client and download the file that cpan is looking for.

      Thanks a lot for the suggestion, but I did do that before I wrote in, and it works without a problem. But then I am manually going to the correct directory on my own system, and that is where the automated system is failing.

      David

Re: Net::FTP is NEVER successful
by Angharad (Pilgrim) on Jul 28, 2005 at 16:43 UTC
    Just out of interest, why use Net::FTP? I've always found that something along these lines works a treat. All you need is a text file read from the command line stating which files you require (although you can change this obviously if you arent keen)
    #!/usr/bin/perl list = $ARGV[0]; $ftp = "/usr/bin/ftp"; $ftptmp="filename.txt"; $ftphost = "<ftp host>"; $ftpdir = "<ftp directory>"; open(LIST, "$list") || die "ERROR: Unable to open $list FILE: $!\n"; while(<LIST>) { @fields = split; $file = $fields[0]; # get file from ftp site print "Retrieving file from FTP site ...\n"; open(FTP, "|$ftp -n $ftphost > $ftptmp"); print FTP "user anonymous "; print FTP "password <email address>\n"; print FTP "cd $ftpdir\n"; print FTP "get $file\n"; print FTP "bye"; }
    Not sure if this is quite what you are after, but it might be useful generally speaking.
    p.s. Could you please do something about the font .. I think you have everything wrapped around code tags at the moment making your post rather difficult to read. lol

      Thanks for this. It looks like a script I will use.

      The reason I used the automated system is that, as a newbie, I don't know which directories .tar.gz files should be downloaded to on my system. Also, at the beginning, there are large numbers of tarballs to download. It's nicer to use cpan's automated discovery of prerequisite packages that need to be downloaded than to discover them one by one.

      Thanks for your help

      David