php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52395 ftp_connect only uses DNS hostnames
Submitted: 2010-07-21 22:09 UTC Modified: 2021-02-28 04:22 UTC
Votes:7
Avg. Score:4.0 ± 0.8
Reproduced:6 of 7 (85.7%)
Same Version:5 (83.3%)
Same OS:4 (66.7%)
From: john-ubuntu at cornerstonelinux dot co dot uk Assigned: cmb (profile)
Status: No Feedback Package: FTP related
PHP Version: 5.3.2 OS: Ubuntu 10.04
Private report: No CVE-ID: None
 [2010-07-21 22:09 UTC] john-ubuntu at cornerstonelinux dot co dot uk
Description:
------------
If "localhost" is present in /etc/hosts but does not resolve via DNS then ftp_c\
onnect will not connect to it.

Most well setup DNS systems will have a "localhost." zone that resolves to 127.\
0.0.1, but this is not compulsory and some ISPs do not do this.

It is traditional for UNIX systems to be able to use local names as defined in \
/etc/hosts for basic names resolution before DNS.

This bug does not appear to occur in other PHP network functions such as IMAP o\
r SMTP, and did not appear in PHP 5.2.4 on Ubuntu 8.04 (and earlier).

I first noticed this bug when I upgrade a mail server from Ubuntu 8.04 to Ubunt\
u 10.04 and the Squirrelmail autorespond plugin (which uses ftp_connect) report\
ed a "failed to connect" error.

To replicate this problem you will have to test on a system that does not resol\
ve "localhost" via DNS. Use the "host" command to check you can not do this:    
--------
$ host -v localhost
Trying "localhost.uk.fabit.net"
Trying "localhost"
Host localhost not found: 3(NXDOMAIN)
--------


Test script:
---------------
<?php
	$ftp = ftp_connect($ftphost);
	if (!$ftp) {
		print "FTP connection failed";
	}
?>


Expected result:
----------------
An ftp connection with no error message.


Actual result:
--------------
No ftp connection attempt and my error message "FTP connection failed".


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-21 22:12 UTC] john-ubuntu at cornerstonelinux dot co dot uk
New description with better line wrapping:

If "localhost" is present in /etc/hosts but does not resolve via DNS then ftp_connect will not connect to it.

Most well setup DNS systems will have a "localhost." zone that resolves to 127.0.0.1, but this is not compulsory and some ISPs do not do this.

It is traditional for UNIX systems to be able to use local names as defined in /etc/hosts for basic names resolution before DNS.

This bug does not appear to occur in other PHP network functions such as IMAP or SMTP, and did not appear in PHP 5.2.4 on Ubuntu 8.04 (and earlier).

I first noticed this bug when I upgrade a mail server from Ubuntu 8.04 to Ubuntu 10.04 and the Squirrelmail autorespond plugin (which uses ftp_connect) reported a "failed to connect" error.

To replicate this problem you will have to test on a system that does not resolve "localhost" via DNS. Use the "host" command to check you can not do this:    
--------
$ host -v localhost
Trying "localhost.uk.fabit.net"
Trying "localhost"
Host localhost not found: 3(NXDOMAIN)
--------
 [2010-07-21 22:43 UTC] mgdm@php.net
I just tried that using Ubuntu's PHP on 10.04, and it doesn't have that problem. Neither does a plain PHP. Are you sure it's not something local to your setup (like the FTP server listening on a v4 address and PHP resolving localhost to v6?)
 [2010-07-21 22:43 UTC] mgdm@php.net
-Status: Open +Status: Feedback
 [2010-07-21 22:53 UTC] john-ubuntu at cornerstonelinux dot co dot uk
The FTP server is running only on the IPv4 localhost:
--------
$ sudo netstat -vnutlp | grep ftpd
tcp        0      0 127.0.0.1:21            0.0.0.0:*               LISTEN      604/vsftpd      
--------

mgdm@php.net, you suggest that PHP is only resolving IPv6 addresses.
How can I find out if that is the case, and how can I change that?

Also why would this only effect the FTP functions and not effect the
IMAP and SMTP functions?

Could you also run 'host -v localhost' and compare the output to my
example above to confirm that the system you are using does not have
a DNS server that resolves "localhost" (because most do).
 [2010-07-22 14:36 UTC] john-ubuntu at cornerstonelinux dot co dot uk
-Status: Feedback +Status: Open
 [2010-07-22 14:36 UTC] john-ubuntu at cornerstonelinux dot co dot uk
Setting status back to "Open" as feedback provided.
 [2010-09-23 00:13 UTC] emperorshishire at gmail dot com
I just recently ran into this problem.  I'm using proftpd as an ftpd.  Proftpd was initially configured to run from inetd, but I reconfigured it to run standalone.  The difference was that when configured to run from inetd, it was running only on ipv4, and when reconfigured to run standalone, it runs on both ipv4 and ipv6.  Something is definately going on with ipv4/6 resolution here.
 [2021-02-19 16:06 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-02-19 16:06 UTC] cmb@php.net
Is this still unresolved for any of the actively supported PHP
versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-02-28 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC