I have a code I am trying to connect to a different server via PHP FTP connection.
I know that I am actually connecting to the server.
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
var_dump($login);
when I vardump the $login, I get a TRUE.
When I try to upload a file I get a 'error uploading file' so I tried to just pull a list of files on the connection:
$file_list = ftp_nlist($ftp_conn, ".");
var_dump($file_list);
It's only returning bool(false).
I know the connections has files because I can view them via FileZilla with the same credentials.
Any idea what might be wrong? Is it possible a server setting that isn't allowing me to use this PHP script from a shared server?
Most typical cause of problems with ftp_list (ftp_nlist, ftp_put and other functions that require separate FTP data connection) is that PHP defaults to the active mode. And in 99% cases, one has to switch to the passive mode, to make the directory listing and transfer working. Use the ftp_pasv function.
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass) or die("Login failed");
// turn passive mode on
ftp_pasv($ftp_conn, true) or die("Unable switch to passive mode");
See my article on the active and passive FTP connection modes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With