Jump to content


Photo

PHP FTP connection problems


  • Please log in to reply
8 replies to this topic

#1 leedude

leedude
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 19 July 2006 - 11:38 AM

I'm a sort of php newbie(at least i think so) and i am trying to connect to my ftp server which is on the same computer as my web server(Fedora Core 5 with MYSQL Server, Pure-ftpd, Apache 2 and PHP 5). I have just finished learning what i need to about sql and php, so now i moving onto ftp. I have started with a simple script to connect to the ftp server, but it just returns the error message.
<?php
$ftp_server = "localhost";
$conn_id = ftp_connect($ftp_server,21) or die("Couldn't connect to $ftp_server");
?>

Why is this happening? i can access the ftp server by conventional means (eg:typing "ftp localhost" at the linux command line or accessing it through an internet browser).
I have tried refering to the ftp server in different ways, like as 192.168.0.7(network ip address) or 86.131.190.81(internet ip).
Any help would be much appreciated.

#2 designationlocutus

designationlocutus
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 19 July 2006 - 01:40 PM

Do you have a username and password set for the FTP server?

#3 leedude

leedude
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 19 July 2006 - 04:09 PM

Yes, i have several, but it is set up in such a way that anonymous access works aswell eg:

ftp://86.131.190.81 goes to the anonymous account( a linux mirror)
ftp://webupload@86.131.190.81 goes to the account for upload to my web server.

Anyway, i thought the username and password details were only needed in the ftp_logon thing.

#4 leedude

leedude
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 July 2006 - 11:04 PM

ok, ive tried the script with ftp.at.debian.org and other ftp sites. same result.
Please help someone. the --ftp-enable option is on in my php configure command by the way.

#5 designationlocutus

designationlocutus
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 24 July 2006 - 09:52 AM

Try it with your passwords and see what happens.

#6 leedude

leedude
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 24 July 2006 - 04:35 PM

ok, ive done a login with the username and password. Same result.

<?php
$ftp_server = "192.168.0.7";
$ftp_user_name = "username";
$ftp_user_pass = "password";
$conn_id = ftp_connect($ftp_server) or die("ERROR 1"); 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("ERROR 2");
?>

This produces an ERROR 1(with the connection)
It seems that there is some kind of problem between my ftp program, and my php program.
is there any kind of apache or php.ini setting that would fix this?

#7 designationlocutus

designationlocutus
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 25 July 2006 - 10:07 AM

Try and add passive mode to your script and see if the result changes (place it after the ftp_login function)

<?php
ftp_pasv($conn_id, true);
?>


#8 leedude

leedude
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 26 July 2006 - 07:03 PM

Nope, no effect. It seems that the problem is with ftp_connect.

#9 myron

myron
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationSalt Lake City, UT

Posted 28 December 2006 - 12:28 AM

Did you ever find a solution to your ftp_connect problem?  If so, what was it?  I'm having the same problem.

Myron
Myron, the PHP Neophyte

When was the last time you did something for the first time?
If you always do what you've always done you'll always get what you've always got.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users