ftp_nlist命令不起作用 [英] ftp_nlist command not working

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

问题描述

我正在使用以下代码↓连接到ftp服务器并获取文件列表.它可以在我的本地计算机(Fedora 11)上正常运行,但不能在生产环境(运行Ubuntu)上使用,该环境下ftp_nlist方法返回false.

I'm using the following code↓ to connect to a ftp server and get a list of files. It works ok on my local machine(Fedora 11) but not on production (running Ubuntu) where the ftp_nlist method returns false.

$ftpInfo = array('directory' => 'somewebsite.com',
                 'user' => 'someuser',
                 'password' => 'somepass',
                 'port' => 21,
                 'timeout' => 30);
$connectionId = ftp_connect($ftpInfo['directory'], 
                            $ftpInfo['port'], 
                            $ftpInfo['timeout']);

$loginResult = ftp_login($connectionId, $ftpInfo['user'], $ftpInfo['password']);

$files = ftp_nlist($connectionId, '.');

var_dump($files);
ftp_close($connectionId);

返回我机器上的文件数组,而在生产中返回false.

Returns an array of files on my machine and false on production.

使得这特别烦人的是,在两种情况下,它都能成功连接并登录.

What makes this particularly annoying is that on both of the cases it manages to connect and login and successfully.

var_dump($loginResult);

返回

bool(true)

推荐答案

原来,这与服务器的防火墙配置有关. 登录后切换到被动模式,一切正常.

Turns out this was related to the server's firewall configuration. Switched to passive mode after logging in and it worked ok.

ftp_pasv($connectionId, true);

这篇关于ftp_nlist命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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