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

Hi, this one's a stumper.

I'm getting an error message when I try to change
directories after a succesful connection to an FTP server.

Here is what the error message looks like:

Can't cd: Net::FTP=GLOB(0x18326f4)->message

Here is a sample of the code:

-----------------------------------------

$ftp=Net::FTP->new("Gondor",Timeout=>240) or $newerr=1;
die "Can't ftp to ftp://ebizftp.honda.com : $!" if
$newerr;
print "Connected\n";

$ftp->cwd("\/Frodo\/") or $newerr=1;  *** HERE IS WHAT GIVES THE ERROR
die "Can't cd: $ftp->message \n" if $newerr;
$ftp->quit if $newerr;

$ftp->quit;


--------------------------------------------

Your help is greatly appreciated.

Brent
  • Comment on FTP'ing to an FTP location that doesn't require login.

Replies are listed 'Best First'.
Re: FTP'ing to an FTP location that doesn't require login.
by daxim (Curate) on Jul 18, 2007 at 00:08 UTC
    use Net::FTP qw(); my $ftp = Net::FTP->new( 'ftp.kde.org', Timeout => 5, ) or die "Could not connect: $!"; warn "Connected\n"; $ftp->cwd("\/pub\/") or warn "Could not change dir: ".$ftp->message."\ +n"; $ftp->quit; __END__ $ perl 627154.pl Connected Could not change dir: Please login with USER and PASS.

Re: FTP'ing to an FTP location that doesn't require login.
by quester (Vicar) on Jul 18, 2007 at 07:37 UTC
    Daxim's point in a nutshell is that string interpolation doesn't do method references, so
    "Can't cd: $ftp->message \n"
    really means
    "Can't cd: " . $ftp . "->message \n"
    rather than
    "Can't cd: " . $ftp->message . " \n"
Re: FTP'ing to an FTP location that doesn't require login.
by sago (Scribe) on Jul 18, 2007 at 09:34 UTC

    use Net::FTP;

    $server="test.const.com";
    $username="p2345ui";
    $password="yuioplk";
    $dir="test_dir/test";
    $ftp = Net::FTP->new($server, Timeout => 75, Debug => 0, BlockSize => 1024) or print "test";

    $ftp->login($username,$password) or print "unable to login";
    if ($ftp)
    {
    print "success login";
    }
    $ftp->cwd($dir) or print "unable to change directory";
    if ($ftp)
    {
    print "success dir change";
    }
    @dirlist = $ftp->ls();
    foreach $file (@dirlist) {
    print "found $file\n";
    }