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

Hello Monks,

I am newbie, so plese bear with me. I am running below code but it does not download "robots.txt"

use strict; use Net::FTP; my $ftpobj = Net::FTP-> new("ftp.cpan.org"); $ftpobj -> login ("anonymous", "nowhere"); $ftpobj -> cwd ("/pub"); $ftpobj -> get ("robots.txt"); $ftpobj -> quit;

The file is present on ftp.cpan.org. My scripts runs fine as I get "0" when I run "echo $?, however, it does not download the file. could you tell me where I am going wrong.

Thanks.

Replies are listed 'Best First'.
Re: Net::FTP module not able to download file
by Khen1950fx (Canon) on Mar 01, 2012 at 21:23 UTC
    You're after the wrong robots.txt. You want the one located in /pub/CPAN:
    !/usr/bin/perl use strict; use warnings; use Net::FTP; use constant HOST => 'ftp.cpan.org'; use constant DIR1 => '/pub/CPAN'; use constant FILE1 => 'robots.txt'; my $ftp = Net::FTP->new( HOST, Debug => 1, Passive => 1, Timeout => 1 ); $ftp->login('anonymous'); $ftp->cwd(DIR1); $ftp->ascii; $ftp->get(FILE1); $ftp->quit;
Re: Net::FTP module not able to download file
by JavaFan (Canon) on Mar 01, 2012 at 21:14 UTC
    You're not checking any of the return values. Perhaps the creation of the object fails. Perhaps the login fails. Perhaps the cwd fails. Perhaps the get fails. We cannot magically deduce what fails.

    Since you're not dying, nor exiting with a non-zero value, its exit value will be 0. Perl will not magically exit with a non-zero value because some operation you did did not give you the result you expected.