What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



ftp_rawlist — Gets a list of files with file information.


array ftp_rawlist(, );
: FTP stream
: A directory


A list of files with extra information on success or FALSE on error


Returns a list files with extra information. The extra information is based on the type of FTP server. This function sends a "LIST" command to the server.


PHP 3>= 3.0.13, PHP 4 >= 4.0b4


Example 371. Get extra file information

// This script will get a directory listing and display
// it in a nicely-formatted table, providing your FTP server
// returns strings in this format:
// -rwx------ 1 user group 1234 Mar 15 19:31 file name.ext

// Define our configuration variables
$ftp_server = "my.ftp.server";
$ftp_username = "username";
$ftp_password = "password";
$dir = "/pub";

// Connect to the server and log in
$ftpStream = ftp_connect($ftp_server)
   or die("Could not connect to FTP server.");
$loginResult = ftp_login($ftpStream, $ftp_username, $ftp_password)
   or die("Could not log in to FTP server.");

// The regex that splits up the array elements consists
// of 8 sets of multiple non-spaces followed by
// multiple spaces, followed by everything else on
// the line (i.e., the filename).  Regex elements
// in () will be stored, using the ereg() call below
$regex = "^([^ ]+) +[^ ]+ +([^ ]+) +([^ ]+) +";
$regex .= "([^ ]+) +([^ ]+ +[^ ]+ +[^ ]+) +(.+)$";

// Get the array of files
$files_array = ftp_rawlist($ftpStream, $dir);

// Throw away the initial "total 12345" line
// You may not need this line; experiment!
each ($files_array);

// Print out the page and table headers
print "<h1 align=\"center\">Files in directory '$dir' on '$ftp_server'</h1>\n";
print "<table border=\"0\" cellspacing=\"0\" ";
print "cellpadding=\"2\" align=\"center\">";
print "<tr><th>Filename</th><th>Timestamp</th>";
print "<th>Size (bytes)</th><th>User</th><th>Group</th>";
print "<th>Permissions</th>\n";

// Loop through each of the files
// You can use foreach instead of while in PHP4
for ($i=0; $i < count($files_array); $i++) {
   // Just for diagnostics
   //print "$files_array[$i]<br>\n";

   // Alternate colors
   if ($i % 2 == 0)
      $bgcolor = "bgcolor=\"#6699cc\"";
      $bgcolor = "bgcolor=\"#9999ff\"";

   // Split up each of the lines and store the segments
   // in $file_info
   ereg($regex, $files_array[$i], $file_info);

   // Finally, print out the table row containing our data
   print "<tr><td $bgcolor>$file_info[6]</td>";
   print "<td $bgcolor>$file_info[5]</td>";
   print "<td $bgcolor>$file_info[4]</td>";
   print "<td $bgcolor>$file_info[2]</td>";
   print "<td $bgcolor>$file_info[3]</td>";
   print "<td $bgcolor>$file_info[1]</td>";
   print "</tr>\n";

// If you have to ask what these do... :)
print "</table>";

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.