dsgnze6572 2012-05-08 09:58
浏览 51
已采纳

连接到ftp服务器

I am trying to connect to multilple ftp servers using ftp_connect and ftp_login. My code is very simple as given

 foreach ($ftp_accounts as $ftp_account) {
     $connect_id = $ftp_account['server'];
                $user = $ftp_account['user'];
                $pass = $ftp_account['password'];
                echo 'Ftp Server: '.$connect_id.'<br> Username: '.$user. '<br> Password: '.$pass.'<br>';
                if (ftp_login($connect_id, $user, $pass)){
                    echo "| Connected to server " . $connect_id . " as " . $user . '<br>';
                } else {
                    echo "Couldn't connect to $connect_id as $user 
";
                }
 }

I have a table in my database with multiple servers and their credentials. but the code i wrote give me the following error (warning) message

 ftp_login() expects parameter 1 to be resource, string given

and it goes to the else statement for every server.

Any idea what I am doing wrong ?

Thanks in advance

  • 写回答

4条回答 默认 最新

  • doutiaosu2310 2012-05-08 12:47
    关注

    Let me answer my question. First of all the replies I get was all corect options to be checked for such problems I highly appriciate the replies but one thing you also need to check is that wether your server firelwall allows to connect to any outgoing ftp server or not ? If it does not allow you to connect then even with everything written correct in your code you will not be able to connect to the server. So before testing your code check your server firewall settings.

    It worked for me when i allowed all outgoing connections.

    Once again Thanks for the replies

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?