PHP ftp_rawlist() Function
The PHP ftp_rawlist() function returns a detailed list of files in the given directory.
Syntax
ftp_rawlist(ftp, directory, recursive)
Parameters
ftp |
Required. Specify the FTP connection to use. |
directory |
Required. Specify the directory path. May include arguments for the LIST command. Use "." to specify the current directory. |
recursive |
Optional. Specify whether to send 'LIST' or 'LIST -R' command to the server. If sets true, the function sends 'LIST -R' command. By default it sends LIST command. |
Return Value
Returns an array where each element corresponds to one line of text. Returns false when passed directory is invalid. The output is not parsed in any way.
Example:
The example below shows the usage of ftp_rawlist() function.
<?php //FTP server to use $ftp_server = "ftp.example.com"; //set up a connection or die $ftp = ftp_connect($ftp_server) or die("Could not connect to $ftp_server"); if($ftp) { //trying to login if(@ftp_login($ftp, $ftp_user, $ftp_pass)) { //getting the file list for / $filelist = ftp_rawlist($ftp, '/'); //displaying the file list var_dump($filelist); } else { echo "Couldn't connect as $ftp_user\n"; } //close the connection ftp_close($ftp); } ?>
The output of the above code will be:
array(3) { [0]=> string(56) "drwxr-x--- 3 user group 4096 Jul 12 11:18 public_ftp" [1]=> string(57) "drwxr-x--- 15 user group 4096 Nov 3 12:31 public_html" [2]=> string(64) "lrwxrwxrwx 1 user group 11 Jul 12 12:46 www -> public_html" }
❮ PHP FTP Reference