Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect with FTP server with PHP , ftp_connect()

Tags:

php

ftp

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

<?php

$ftp_server = "http://ftp.mozilla.org/pub/mozilla.org/";

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

?>

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.

like image 671
Quazi Farhan Avatar asked Jun 30 '11 14:06

Quazi Farhan


2 Answers

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.

like image 152
Michael Berkowski Avatar answered Sep 24 '22 12:09

Michael Berkowski


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

like image 26
Pekka Avatar answered Sep 22 '22 12:09

Pekka