PHP ftp_connect

Dude Lebowski asked:

I try to use the php ftp_connect fucntion on my dedicated server and I’m unable to establish a connection:

$conn_id = ftp_connect($ftp_server, 21) or die("Unable to connect to $ftp_server") ;

I’m sure the function is available as I test with :


and it returns true

When I ftp the server through the shell I can reach it so I guess it’s not a firewall issue.
Am I missing something else ?

Thanks for your precious advices

My answer:

PHP will log a warning if ftp_connect fails. However, you may have logging disabled or going to an unexpected place. Check your php.ini and related configuration files to ensure that logging is enabled and to specify where the logs are written.

To diagnose this problem without access to logs, try running PHP from the command line. For instance:

$ php
<?php $x = ftp_connect("");


PHP Warning:  ftp_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 1

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.