I’m having trouble connecting to my ftp server in PHP. I’m able to log in using the telnet command from the cmd prompt, so the server/user/password is correct, but when I attempt to connect using PHP I get an error:
Warning: ftp_login() [function.ftp-login]: Login incorrect. in
/hermes/bosweb/web232/b2323/ipg….
When I comment out my server/user/pass and replace with a public anonymous ftp server the code works (as shown below). I’ve been searching for an answer for the past week but still have no clue what I’m missing or where else to look. Also, I’m a php/server newbie, so it might be something really simple. Any help is greatly appreciated!
<?php
/*
// (does not work)
$ftp_server = "ftp.*****.com";
$ftp_user = "******";
$ftp_password = "*****";
*/
$ftp_server = "ftp.gnu.org";
$ftp_user = "anonymous";
$ftp_password = "none";
/* connect */
$ftp_connection = @ftp_connect($ftp_server);
if (!$ftp_connection) die('could not connect.');
/* login */
$ftp_login = @ftp_login($ftp_connection, $ftp_user, $ftp_password);
if (!$ftp_login) die('could not login.');
/* enter passive mode */
$ftp_passive = @ftp_pasv($ftp_connection, true);
if (!$ftp_passive) die('could not enable passive mode.');
/* get listing */
$ftp_listing = ftp_nlist($ftp_connection, ".");
foreach ($ftp_listing as $file){
echo "<div>".$file."</div>";
}
ftp_close($ftp_connection);
?>
Sorry, rookie php mistake. I was trying to access my ftp server from php code on that server… I guess that doesn’t work. I ran code from another server and works fine. Thanks anyway!