How can I list all directories using FTP?

3

I've tried ftp_nlist () and ftp_rawlist () but return is always an empty array.

The question of Access / Authentication is ok, will only try to read a list if the same already connected to a user:

Example:

$dados = array('host' => 'localhost', 'usuario' => 'teste', 'senha' => '123456');

$conn = ftp_connect($dados['host']);

if (ftp_login($conn, $dados['usuario'], $dados['senha'])):
//   var_dump(ftp_nlist($conn, '.'));
   var_dump(ftp_rawlist($conn, '/'));
endif;
    
asked by anonymous 04.02.2016 / 19:50

1 answer

3

I tested your code on my server and it works perfectly both ftp_nlist() and ftp_rawlist()

Are you working locally or on a host? if hosted on a host try adding the domain to the user, eg

$dados = array('host' => 'localhost', '[email protected]' => 'teste', 'senha' => '123456');

If you're still experiencing problems try adding to your code:

ftp_pasv($conn,true);

This command changes the passive mode to on or off. In passive mode, data connections are initiated by the client, rather than the server. This may be necessary if the client is behind a firewall.

Note that ftp_pasv() can only be called after login has been successful, otherwise it will fail.

    
10.02.2016 / 13:43