Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Net::FTP

by Anonymous Monk
on Jun 09, 2016 at 07:45 UTC ( #1165205=note: print w/replies, xml ) Need Help??


in reply to Re^2: Net::FTP
in thread Net::FTP

Hi,

I am trying to implement this $ftp->login.
But if the login is unsuccessful, I am getting the following error message and program gets terminated.
Uncaught exception from user code: Cannot login Login incorrect.

Is there any way to catch / handle this unsuccessful login, so that the program can continue?

Replies are listed 'Best First'.
Re^4: Net::FTP
by stevieb (Canon) on Jun 09, 2016 at 12:36 UTC

    Untested:

    my $logged_in = eval { $ftp->login($un, $pw); 1; }; if (! $logged_in){ if ($@ =~ /login incorrect/i){ # do stuff, perhaps keep asking user for un/pw and # re-attempt login in a loop } else { # might not be a login error... # handle different exception } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2021-12-09 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?