douli1854 2010-07-14 23:17
浏览 129
已采纳

MAMP:本地环境......连接到ftp不起作用?

i love working with mamp ( i have the pro version). i'm currently trying to connect to a ftp server and list the files up there. however the connection is successful but it won't list the files.

$contents = ftp_nlist($conn_id, $path);

returns bool(false)

however the script is working if i run it on my real webserver. is there maybe some preference i have to set to get it working locally as well?

regards

  • 写回答

3条回答 默认 最新

  • duankang8114 2010-07-15 02:28
    关注

    I have MAMP so I did a little testing using the first example in the php manual page for ftp_nlist, and was getting the same error as you (bool(false)). Turns out, if using that code:

    // set up basic connection
    $conn_id = ftp_connect($ftp_server);
    
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    
    // get contents of the current directory
    $contents = ftp_nlist($conn_id, ".");
    
    // output $contents
    var_dump($contents);
    

    and the login fails either because of a bad username or password, if will fail with the bool(false) message.

    Better to do something that will give you better info as to where it failed (if it does fail):

    // set up basic connection variables
    $ftp_server='127.0.0.1';
    $ftp_user_name='user';
    $ftp_user_pass='pass';
    
    //initiate connection
    $conn_id = ftp_connect($ftp_server);
    
    
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die ('login failed');
    
    // get contents of the current directory
    $contents = ftp_nlist($conn_id, ".") or die ('could not get contents');
    
    // output $contents
    var_dump($contents);
    

    I tested this and it works. Given the right credentials, it will log in and dump the dir. If the credentials are bad, it will die with a 'login failed' message. If the path is bad, it will die with a 'could not get contents' message; so at least if it does break down you'll have a better idea of where.

    HTH

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

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题