|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47110 Can not use ftp functions behind firewall
Submitted: 2009-01-15 08:39 UTC Modified: 2009-01-15 17:41 UTC
From: konix dot net at du dot t-com dot hr Assigned:
Status: Closed Package: FTP related
PHP Version: 5.2.8 OS: Cent OS (Latest patch)
Private report: No CVE-ID: None
 [2009-01-15 08:39 UTC] konix dot net at du dot t-com dot hr
I'm trying to connect to FTP server from a script.
Script is behind firewall.
Only FTP port is allowed (application/script is to be used in PCIDSS enviroment).

We tried same script on other servers and no problem accured at all. This could be a firewall / web application firewall (mod_security) issue but we're not sure.

Reproduce code:
$ftp_array = array(
 // Host, user, pass

$port = 21;
$network_timeout = 30;

echo "Connecting...\n";

// Connect
$ftp_connection = ftp_connect($ftp_array['host'], $port, network);

if ($ftp_connection) {
	// Login
	if ($login = ftp_login($ftp_connection, $ftp_array['user'], $ftp_array['pass'])) {
		// Pasive mode
		ftp_pasv($ftp_connection, true);
		// Change dir
		ftp_chdir($ftp_connection, "in");
		// Get dir listing
		$contents = ftp_nlist($ftp_connection, ".");
		// Echo list
		echo '<pre>';
		echo '</pre>';
	} else {
          echo "Can't login to remote server.";

} else {
  exit("Can't connect to remote server.");


Expected result:
    [0] => .
    [1] => ..
    [2] => 11829_RATE_39.txt

Actual result:
Warning: ftp_nlist() [function.ftp-nlist]: php_connect_nonb() failed: Operation now in progress (115) in /var/www/html/public_html/ftp_test.php on line 30


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-15 12:47 UTC]
IIRC, it's just a buggy FTP server issue.
 [2009-01-15 17:21 UTC] konix dot net at du dot t-com dot hr
FYI for anyone else looking for answer:
- when behind firewall, you will surly set your ftp connection in PASV mode.

Be sure to configure your firewall in a right way as you will need port open in upper ranges (from 1024).

Once this is done, all PHP FTP function in PSV mode work as they should.
 [2009-01-15 17:41 UTC] konix dot net at du dot t-com dot hr
Fix firewall and it will work.
 [2011-09-10 16:05 UTC] abrender at elitehosts dot com
If you're seeing 'failed: Operation now in progress (115)' and you've already 
switched into passive FTP mode then either your firewall needs to be fixed OR the 
ftp server is returning a private RFC1918 IP address in response to the PASV 
command which PHP is then trying to connect to and timing out. I've detailed this 
issue at
nightmare/ and posted an entry at with a patch to fix the issue at - please vote for that feature fix if you 
want it included in future PHP releases.
 [2017-07-27 22:24 UTC] raffaele dot mancoletti at accenture dot com
the problem is that path of destination file is incorrect. use 

ftp_chdir($conn_id, FTP_DIRECTORY_DEST);										print_r(ftp_nlist($conn_id, "."));

to verify if path is correct.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 16:05:46 2022 UTC