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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php ftp_connect(); help needed... 2

Status
Not open for further replies.

fowlerlfc

MIS
Mar 20, 2002
136
US
trying to connect to my server with the following script:

<?php

$ftp_server = "xxxxxx";
$ftp_user_name = "xxxx";
$ftp_user_pass = "xxxxx";
// set up basic connection
$conn_id = ftp_connect($ftp_server, 21);
// 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!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}

?>

i get the following server error:
Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/sites/site4/web/ftp.php on line 11

is it my script? can someone let me know what my problem is?

thanks in advance.
 
Did you know that the PHP online manual states that ftp_connect() returns an FTP stream on success and boolean value FALSE on failure?

FALSE could be the boolean value mentioned in your error message. If this is correct, I'd guess ftp_connect() can't connect to the specified FTP server.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Try it without the 21 on it, its 21 by default. Also, add a die to see if its crapping out when it tried to connect. That way we can isolate if its the server or your script.

$conn_id = ftp_connect($ftp_server) or die("Im Broke!");
 
Works for me just fine if I use a server I know I'm gonna succeed on, therefore follow tha advice above re error handling.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
nawlej and karver,

thanks for your help. i'd never used the ftp php functions before so i wasn't sure if it was the script or server! your help isolated the problem for me! my php install must be bad, as i know that i enabled ftp and it even shows it in phpinfo().

thanks again!
 
It may or may not be your PHP installation. It could be a network issue.

For example, suppose that your PHP machine and your FTP machine are on a network with non-routeable addressses, and that your firewall or router allows routeable addresses from the internet to access that FTP server. Let's further assume that the FTP server can be reached through the fully-qualified domain name ftp.domain.fu, and that ftp.domain.fu resolves to the routeable address to your FTP server.

If within PHP you use "ftp.domain.fu" as your FTP host with ftp_connect(), your router will likely not allow machines on your internal network to connect to that FTP server using the routeable address. You'd have to specify the internal address of the FTP server.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top