Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ftp_nlist command not working

Tags:

php

ftp

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)
like image 518
vise Avatar asked Oct 22 '09 18:10

vise


1 Answers

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);
like image 177
vise Avatar answered Oct 24 '22 19:10

vise