How to get error if FTP server is invalid.?

百般思念 提交于 2019-12-21 20:57:19

问题


I am trying to connect FTP Server ushin php code, if i put FTP-Servaer Name Invalid then its end the script and not return false in $conn_id.

code spinet:

$conn_id = ftp_connect($_POST['ftp_server']);
if($conn_id)
{
   echo "invalid server name";
}
else
{
   if(ftp_login($conn_id, $_POST['ftp_username'], $_POST['ftp_password']))
   {
    $connection_status = 'tested';
    echo "<script>alert('Correct FTP login credentials');</script>";
   }
}

its stop script at first line and not shows echo "invalid server name";

error

ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known.

i need to alert user if he puts invalid server-name. Thanks !!!


回答1:


try this and you done

$conn = @ftp_connect("ftp.funnybunnyvideos.in");
if($conn)
{
    echo 'server name is valid';
}
else
{
    echo 'server name is invalid';
}

Cheers !!!




回答2:


I think you should just need to change if($conn_id) to if($conn_id === FALSE)

EDIT

Try running this:

<?php
$c = ftp_connect('ftp.mozilla.org');
var_dump($c);

$c = ftp_connect('abcdefg');
var_dump($c);
?>

You should get this:

resource(2) of type (FTP Buffer) Warning: ftp_connect()

[function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\abc\def.php on line 5

bool(false)



来源:https://stackoverflow.com/questions/10619903/how-to-get-error-if-ftp-server-is-invalid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!