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


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


    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 } }