How do I list all directories using FTP?

Asked

Viewed 617 times

3

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

The Access/Authentication question is ok, you will only try to read a list if it already connected with 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;
  • Already tried using passive mode: ftp_pasv($Conn, true);

  • I even tried but my problem at first is not this ftp_pasv is good for when you have firewall but ftp I created and on my own machine

  • Other ftp functions like ftp_get work: ftp_get($Conn, 'arquivolocal.Xyz', 'arquivoremoto.Xyz', FTP_ASCII, 0) ?

  • Already checked if you are allowed to list on FTP?

  • yes, because if I do an ftp://user:password@localhost I can authenticate and view all folders, I asked a colleague of mine to access my ip and it worked too

1 answer

3


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

Are you working locally or on a host? if you are hosted on a host try including the domain in the user, e.g.:

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

if you still have problems try adding to your code:

ftp_pasv($conn,true);

This command changes the passive mode on or off. In passive mode, data connections are started by the client instead of the server. This may be necessary if the client is behind a firewall.

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

  • ftp_pasv() returns me true, ftp_nlist() shows me only the root directory and ftp_rawlist() returns me empty.

  • how did you create, via Cpanel? , have other directories or files inside the user folder? has already tested with the same data whether you can see the files in an ftp client?

  • if I access ftp from the terminal with the same user I can list

  • but it is a local ftp or a Webhost?

  • This is a local FTP

  • will not be a problem of permissions?

  • In php ? why does the terminal work.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.