Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Net::FTP Error Handling

by grantm (Parson)
on Jul 16, 2002 at 09:34 UTC ( #182027=note: print w/replies, xml ) Need Help??

in reply to Net::FTP

When a Net::FTP operation fails, you really want to get the error details so you know what failed. It always takes me a while to find the details in the Net::FTP docs so I thought I'd post here:

Initial Connection: the connection is established when you create the object. If the connect fails, new() will return undef and the error message will be in $@:

my $ftp = Net::FTP->new($destserv) || die "Connect to $destserv failed: $@";

Commands: if a command fails, the method return value will be undef. The error message can be accessed using the 'message()' method. If you're checking for a particular message, you might be better off using the 'code()' method to get the three digit FTP protocol status code which preceded the message:

$ftp->get($file) || die "get($file) failed: " . $ftp->code() . ": " . $ftp->message();

Replies are listed 'Best First'.
Re: Net::FTP pwd bug?
by mikeock (Hermit) on Oct 12, 2005 at 19:05 UTC
    When using this module. I cannot get the pwd command to work.

    I am connected to an ftp server and am trying to use $ftp->pwd() and I get nothing in return. Is this dumping to a default variable that I am missing or is this really a bug?


      If you are following the above code try something like :
      #!/usr/bin/perl use Net::FTP; my $destserv=""; my $destuser="username"; my $destpass="password"; $ftp = Net::FTP->new($destserv) or die "error connecting\n"; $ftp->login($destuser,$destpass); my $mypath = $ftp->pwd(); $ftp->quit(); print "FTP Path: $mypath";
      Keep in mind that this is untested, its late and I am seriously sleep deprived.
      Have you checked out the documentation? There is a link to examples you can also have a look at.

      Hope this helps


        When that variable is added  my $mypath = $ftp->pwd(): to my code, I get the same results as just trying to call  $ftp->pwd();

        And by the same I mean that there is no repsonse at all. The Box that has the server on it allows me to login and type pwd so I know that it is supported on the server.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://182027]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2021-12-08 02:50 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (34 votes). Check out past polls.