From: php at stock-consulting dot com Operating system: Windows 2000 PHP version: 5.2.4 PHP Bug Type: FTP related Bug description: FTP functions apparently use wrong IP address for PORT in PASV mode
Description: ------------ Situation: the local machine, which executes the PHP script via the command line, sits behind a NAT firefall and needs to retrieve directory listings and files from an FTP server sitting somewhere on the Internet. Passive FTP is required to traverse the firewall. The local machine has the IP address 10.0.0.1 (subnet configured as Class C). The external (WAN) IP of the router/firewall is 80.x.x.x (address partially concealed to protect the, erm, innocent). Now the problem: the script correctly connects to the FTP server and begins to retrieve directory listings (recursively) and files. At some RANDOM point, the following warning appears: Warning: ftp_chdir(): PORT command only accepts client IP address (80.x.x.x !=10.0.0.1). in my_script.php on line 40 This warning then appears both at all further attempts to retrieve directory listings and files. The transfers are not successful. Note that directory and file retrieval works perfectly UNTIL the warning occurs for the first time, at some random time. When the script is restarted, it will again work for some listings and files, until, at some different point, the warning will appear again. Reproduce code: --------------- // Short version, stripped from anything which appeared not so useful for this bug report function remote_scan($path) { global $ftp; ftp_chdir($ftp, $path); $raw_entries = ftp_rawlist($ftp, $path); foreach ($raw_entries AS $line) { $entry = preg_split('@\s+@', $line, 9); if ($entry[4] == 0) { remote_scan($path . $entry[8] . '/'); } else { ftp_get($ftp, 'x:/local_path' . $path . $entry[8], $path . $entry[8], FTP_BINARY); } } } $ftp = ftp_connect('ftp.url', 47624); // server uses non-standard port $login_result = ftp_login($ftp, 'user', 'password'); ftp_pasv($ftp, true); remote_scan('/'); ftp_close($ftp); -- Edit bug report at http://bugs.php.net/?id=42492&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42492&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42492&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42492&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=42492&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=42492&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=42492&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=42492&r=needscript Try newer version: http://bugs.php.net/fix.php?id=42492&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=42492&r=support Expected behavior: http://bugs.php.net/fix.php?id=42492&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=42492&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=42492&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=42492&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42492&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=42492&r=dst IIS Stability: http://bugs.php.net/fix.php?id=42492&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=42492&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=42492&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=42492&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=42492&r=mysqlcfg