Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

I was trying to connect with ftp server using ftp_connect() function of PHP as shown below:


But it returns this error:

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\wamp\www\ftp2.php on line 6

Although this is a very common type of error, I still cannot find any solution. Can anyone provide some possible solutions?

Thank you for your time.

asked Jun 30, 2011 at 14:34

Quazi FarhanQuazi Farhan

1,3857 gold badges16 silver badges29 bronze badges

You must supply only the ftp server hostname, rather than the hostname and directory path, and the irrelevant http:// since this is an FTP connection.

$ftp_server = "ftp.mozilla.org";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// Then chdir to the correct directory:
ftp_chdir($conn_id, "/pub/mozilla.org");

See the full documentation of PHP's FTP functions.

answered Jun 30, 2011 at 14:37

Michael BerkowskiMichael Berkowski

263k45 gold badges434 silver badges380 bronze badges

1

Get rid of the http://, it is not part of the server address.

answered Jun 30, 2011 at 14:35

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

Not the answer you're looking for? Browse other questions tagged php ftp or ask your own question.

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 :

function_exists('ftp_connect')

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

asked Sep 5, 2012 at 8:39

2

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

Ctrl+D

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

answered Sep 5, 2012 at 22:27

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

Michael HamptonMichael Hampton

237k42 gold badges476 silver badges938 bronze badges

Not the answer you're looking for? Browse other questions tagged php ftp or ask your own question.

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

11 Years Ago

Hi

I am trying to connect my server through PHP script as below. But i am unable to reach my server and getting error.

If i connect my server through ftp software with FTPES protocol my server is getting connect

I am getting an Error as

"Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\uploadftp.php on line 13
Cannot connect to host

Please can any one provide me good solution to solve my issue

I advice you to have a deep look into your code or in the internet. This problem could be caused by anything. You could have a typing error, or try to connect to a computer without ftp-server, or your extension doesn't work or your firewall, router...

What about connecting …

Jump to Post

We need more information to solve this issue.

Jump to Post

All 5 Replies

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

sDJh 39 Posting Whiz in Training

11 Years Ago

I advice you to have a deep look into your code or in the internet. This problem could be caused by anything. You could have a typing error, or try to connect to a computer without ftp-server, or your extension doesn't work or your firewall, router...

What about connecting to that computer via a ftp-client?

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

11 Years Ago

Hi

i have explained the thing in the above post itself.

If i connect my server through ftp software with FTPES protocol my server is getting connect

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

sDJh 39 Posting Whiz in Training

11 Years Ago

Hi rpv_sen,

I'm sorry to say, but in my point of view, you haven't.

Not getting access to a FTP-server does not necessary be a fault of PHP.

For some good advice, we actually need more details.
1) The correct server address
2) does it work with file-zilla
3) what about your firewall?
4) anything installed correctly
etc

As I said before, this problem can be caused by almost anything thinkable.

Greetings

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

Nahiyan 7 Junior Poster in Training

11 Years Ago

We need more information to solve this issue.

Ftp_connect(): php_network_getaddresses: getaddrinfo failed: name or service not known

11 Years Ago

hi

Thanks for your reply,

I am able to connect my FTP through file-zilla, that to i have specify the protocol as below

ftpes://domainname.com

we don't have any firewall system.

Reply to this topic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.