PHP ftp_nlist无法正常工作 [英] PHP ftp_nlist is not working

查看:49
本文介绍了PHP ftp_nlist无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");

if (@ftp_login($ftp_conn, $ftp_username, $ftp_userpass))
{
    $path = "./";
    $path1="./test";
    $file = "test.txt";
    $file_list = ftp_nlist($ftp_conn,$path);
}
// close connection
ftp_close($ftp_conn);

以上是我正在使用的代码.在我的Windows本地计算机,Windows服务器计算机,Linux本地计算机上,它对我来说工作正常,但在Linux服务器计算机上却以某种方式失败. ftp_nlist 返回 false .有人可以告诉我原因吗?

The above is the code which I am using. It is working fine for me on my Windows local machine, Windows server machine, Linux local machine, but somehow it fails on the Linux server machine. ftp_nlist returns false. Can someone tell me what might be the reason?

任何帮助表示赞赏.谢谢.

Any help appreciated. Thank you.

推荐答案

ftp_nlist (或其他任何传输命令,例如 ftp_get ftp_put ftp_rawlist )是PHP默认为FTP活动模式.在99%的情况下,必须切换到FTP被动模式才能使传输正常进行.使用 ftp_pasv 函数.

Most typical cause of problems with ftp_nlist (or any other transfer command like ftp_get, ftp_put, ftp_rawlist) is that PHP defaults to the FTP active mode. And in 99% cases, one has to switch to the FTP passive mode, to make the transfer working. Use the ftp_pasv function.

$connect = ftp_connect($ftp) or die("Unable to connect to host");
ftp_login($connect, $username, $pwd) or die("Authorization failed");
// turn passive mode on
ftp_pasv($connect, true) or die("Passive mode failed");

另请参见主动和被动FTP连接模式上的文章a>.

See also my article on the active and passive FTP connection modes.

这篇关于PHP ftp_nlist无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆