Solved

PHP & FTP:  ftp_connect error - php_network_getaddresses: getaddrinfo failed: No such host is known

Posted on 2006-11-04
5
8,350 Views
Last Modified: 2007-12-19
Hi all,

I'm a PHP noob, so please excuse my ignorance....

I have the following script;
<?php

// define some variables
$ftp_server= "ftp://ftp2.bom.gov.au/anon/gen/fwo";
$ftp_user_name= "anonymous";
$ftp_user_pass= "webmaster@aquaticadventures.com.au";
$local_file = "4day.txt";
$server_file = "IDV10450.txt";


// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed!<br>";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name<br>";
        die;
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name<br>";
    }

// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
   echo "Successfully written to $local_file\n";
} else {
   echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

?>

Which gives the following error;
Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\Elysian Visions\AA test page\4day.php on line 12

Warning: ftp_login() expects parameter 1 to be resource, boolean given in D:\Elysian Visions\AA test page\4day.php on line 15
FTP connection has failed!
Attempted to connect to ftp://ftp.bom.gov.au for user anonymous

I'm not sure why it won't connect to the FTP server, which is a public server provided by the Bureau of Meteorology (Government), hence the user & password.

Do I have to do something in php.ini to allow FTP via PHP? Or do I need to have an IP address to connect to instead of ftp://ftp2.bom.gov.au/anon/gen/fwo? Or do I have a stupid syntax error I can't seem to spot?

Thanks a million for your help.

The BFG :D
0
Comment
Question by:elysiandc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:ch2
ID: 17875561
change this:

$ftp_server= "ftp://ftp2.bom.gov.au/anon/gen/fwo";

for

$ftp_server= "ftp2.bom.gov.au";

and this:

$server_file = "IDV10450.txt";

for

this:

$server_file = "/anon/gen/fwo/IDV10450.txt";
0
 

Author Comment

by:elysiandc
ID: 17875611
Hey Ch2,

Thanks for the quick reply - I gave that a shot and get the same errors...

Any other tips?

Cheers

BFG
0
 
LVL 11

Accepted Solution

by:
ch2 earned 125 total points
ID: 17875642
give a try to this

$ftp_server= "134.178.63.130";


0
 

Author Comment

by:elysiandc
ID: 17875796
It worked! You're a chanpion!

Thanks a million.  :D
Can I ask where you got the IP from? Also wondering - does this mean that for $ftp_server you can't use a URL, only an IP addrress?

Again, thanks for your help.

The BFG
0
 
LVL 11

Expert Comment

by:ch2
ID: 17921524
<<Can I ask where you got the IP from?

well i just resolved the domain you posted.

An easy way to do resolve a domain is to ping the domain name with the ping tool wich comes with windows xp and other operating systems as well.

<<Also wondering - does this mean that for $ftp_server you can't use a URL, only an IP addrress?

You can use an ip address or a domain, both works.

If using a domain you must resolve the domain fisrt. To do it in PHP use gethostbyname()

gethostbyname() could be other option to resolve your issue.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question