morpe

ftp + pregmetch for raw unix listing

Apr 2nd, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <html>
  2. <?php
  3. //require_once ("");
  4. $ftp_host = "localhost";
  5. $ftp_user = "";
  6. $ftp_password = "";
  7. //Connect
  8. echo "<br />Connecting to $ftp_host via FTP...";
  9. $conn = ftp_connect($ftp_host);
  10. $login = ftp_login($conn, $ftp_user, $ftp_password);
  11. //
  12. //Enable PASV ( Note: must be done after ftp_login() )
  13. //
  14. $mode = ftp_pasv($conn, TRUE);
  15. //Login OK ?
  16. if ((!$conn) || (!$login) || (!$mode)) {
  17.        die("FTP connection has failed !");
  18. }
  19. echo "<br />Login Ok.<br />";
  20. //
  21. //Now run ftp_nlist()
  22. //
  23. $file_list = ftp_rawlist($conn, "-a /Ebola/Pubblic");
  24.  
  25. foreach( $file_list as $n => $line)
  26. {
  27.     if (preg_match("/([-dl])([rwxsStT-]{9})[ ]+([0-9]+)[ ]+([^ ]+)[ ]+(.+)[ ]+([0-9]+)[ ]+([a-zA-Z]+[ ]+[0-9]+)[ ]+([0-9:]+)[ ]+(.*)/", $line, $regs) == true)
  28.     {
  29.         //                  permissions             number      owner      group   size        month         day        year/hour    filename
  30.         $listline[$n]["scanrule"]         = "rule-1";
  31.         $listline[$n]["dirorfile"]        = "$regs[1]";     // Directory ==> d, File ==> -
  32.         $listline[$n]["dirfilename"]      = "$regs[9]";     // Filename
  33.         $listline[$n]["size"]             = "$regs[6]";     // Size
  34.         $listline[$n]["owner"]            = "$regs[4]";     // Owner
  35.         $listline[$n]["group"]            = "$regs[5]";     // Group
  36.         $listline[$n]["permissions"]      = "$regs[2]";     // Permissions
  37.         $listline[$n]["mtime"]            = "$regs[7] $regs[8]";    // Mtime -- format depends on what FTP server returns (year, month, day, hour, minutes... see above)
  38.     }
  39. }
  40.  
  41. echo   
  42. "<table border=1>
  43. <!-- ----------------------- -->
  44.     <tr>
  45.         <td>Customer</td>
  46.         <td><b>Akab update package</b></td>
  47.         <td><b>Upload date</b></td>
  48.         <td><b>Download date</b></td>
  49.     </tr>
  50. <!-- ----------------------- -->";
  51.  
  52. for($l =0; $l < count($listline); $l++ )
  53. {
  54.     echo "<tr>";
  55.     echo "<td>".$listline[$l]["owner"]."</td>";
  56.     echo "<td>".$listline[$l]["dirfilename"]."</td>";
  57.     echo "<td>".$listline[$l]["size"]."</td>";
  58.     echo "<td>".$listline[$l]["mtime"]."</td>";
  59.     echo "<tr>";
  60. }
  61. echo "</table>";
  62.  
  63. ftp_close($conn);
  64. ?>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment