in reply to Re: Net::FTP server errors?
in thread Net::FTP server errors?

Get is the only command that will return useful information in $!. If the file doesn't exist, it would print "Bad file descriptor at filename line x." to STDERR.

Replies are listed 'Best First'.
Re: Re: Re: Net::FTP server errors?
by Mr. Muskrat (Canon) on Oct 31, 2002 at 19:48 UTC

    Oops!

    my $ftp = Net::FTP->new("some.host.name") or die $!; would print "Invalid argument at filename line x." to STDERR.

      The fact that in this particular case $! contains something that might look like the right error message doesn't mean the other procedures will be able to use it as well.

      The list of errors that can be found in $! is fixed (and OS dependant). You can find out what it is by

      $lastmsg='noNSensE'; $i = 0; $! = $i; while ($lastmsg ne $!) { $lastmsg = ''.$!; print "$i: $!\n"; $i++; $! = $i; }

      Try also:

      $! = "Hello world"; print "$!\n";

      So as you see it is possible to change the $!, but you can't give a very specific error message.

      What GhodMode wants is

      $ftp->message()

      Of course that doesn't work for the "new Net::FTP", but that was not requested.

      Jenda

        Once again, I am reminded to read the docs on Net::Cmd...

        So then something like this would work nicely, huh?

        #!/usr/bin/perl use strict; use warnings; use Net::FTP; my $ftp = Net::FTP->new("some.host.name") or die "Server not found!\n" +; $ftp->login("anonymous",'me@here.there') or die $ftp->message(); $ftp->cwd("/pub") or die $ftp->message(); $ftp->get("that.file") or die $ftp->message(); $ftp->quit;