3

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?

0

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.