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条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line