I get a server error on the ftp_login line of the following code. How can I gracefully handle connection/login failure?
$serverAddress = 'ftp.someServerAddress';
$connId = ftp_connect($serverAddress);
if($connId) {
if (ftp_login($connId, 'UserName', 'password')) {
// do some stuff
} else {
echo 'login failed';
}
} else {
echo 'connection failed';
}
This will work.
if( ! @ftp_login( $connection, 'USERNAME', 'PASSWORD' ) ){
die( 'Bad login, but no PHP warning thrown.');
}
http://php.net/manual/en/function.ftp-login.php
Sorry forgot to add that the @
symbol before function will suppress errors just as @John Stirling said before me in the comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With