Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP Sum Column in Table 3 27
session dropped in IE 10 19
mysql left join sentence 7 19
showing numeric numbers 2 8
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
The viewer will learn how to count occurrences of each item in an array.
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now