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)
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With