Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting a ftp connect error 1

Status
Not open for further replies.

benedictbutlin

Technical User
Oct 12, 2012
16
GB
I'm trying to connect to an ftp sever but getting the following error...

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /directory/file.php on line 12

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /directory/file.php on line 13

Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /directory/file.php on line 16

Couldn't connect to ftp://ftp2.xxxx.com

From what i've googled, it could be a setting that needs to be configured in the php.ini? if this is so, and based on my error can you advise what i'm meant to change, or maybe the code can be made to work without php.ini changes? here's my code....

Code:
$ftp_server = "ftp://ftp2.xxxx.com";
$ftp_user = "xxxx";
$ftp_pass = "xxxx";

$ftp_connect = ftp_connect($ftp_server);
$ftp_loggedIn = ftp_login($ftp_connect, $username, $password);

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

$loggedIn = ftp_login($ftp_connect,  $ftp_user,  $ftp_pass);

if (true === $ftp_loggedIn) {

echo 'Success!';

} else {

throw new Exception('Unable to log in');

}
 
you are redoing the ftp_connect on line 9 (first connected line 5) but still referencing the the resource handle created on line 5.
 
hey jpadie,

just 1 error remaining...

ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known in /directory/file.php on line 12

Couldn't connect to ftp://ftp2.xxxxx.com

line 12 is this line... $ftp_connect = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

there were quite a few errors in my code (sorry!)... and i've cleaned it up like so, but still returns the error above...

Code:
$ftp_connect = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
$ftp_loggedIn = ftp_login($ftp_conn, $ftp_user, $ftp_pass);

if (true === $ftp_loggedIn) {

	echo 'Success!';

} else {

	throw new Exception('Unable to log in');

}

ftp_close($ftp_connect);
 
i'm full of mistakes today... sorry here's the corrected code but still returns the same error

Code:
$ftp_connect = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
$ftp_loggedIn = ftp_login($ftp_connect, $ftp_user, $ftp_pass);

if (true === $ftp_loggedIn) {

	echo 'Success!';

} else {

	throw new Exception('Unable to log in');

}

ftp_close($ftp_connect);
 
php manual said:
The FTP server address. This parameter shouldn't have any trailing slashes and shouldn't be prefixed with ftp://.

in your first post you prepend the protocol to the server address. you should not do so.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top