ftp_nlist command not working

2019-03-24 01:44发布

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

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

returns

bool(true)

标签: php ftp
1条回答
走好不送
2楼-- · 2019-03-24 02:16

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);
查看更多
登录 后发表回答