Solved

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

Posted on 2006-11-04
5
8,424 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

728 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