Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-04
5
Medium Priority
?
8,651 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 500 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

Technology Partners: 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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

618 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