Zend - The PHP Company




Files and Directories

Add Code


FTP stats  

Type: code fragment
Added by: Navex
Entered: 19/06/2003
Last modified: 09/12/2002
Rating: - (fewer than 3 votes)
Views: 4328
This script parses FTP wu-ftp log file (xferlog) and show some stats sorted by username. Total bytes, bytes by day, incoming and outcoming totals


<?
// read : http://unixhelp.ed.ac.uk/CGI/man-cgi?xferlog+5
// This script parses wu-ftp log file and show some stats sorted by username.
// Total bytes, bytes by day, incoming and outcoming totals
// Works better if you config your '/etc/logrotate.conf' to rotate at monthly basis.
// Tested only at Red-Hat box.
// By  Omar Ballabio -- php@nave.net

$logfile "/var/log/xferlog";
$handle fopen ($logfile"r");
while (!
feof ($handle)) {
    
$buffer fgets($handle4096);
    
$Tline explode(" ",$buffer);
     
        if(
count($Tline)>1){
                 
$FTPstat[$Tline[13]][total_bytes] += $Tline[7];
                 
$FTPstat[$Tline[13]][direction][$Tline[11]] += $Tline[7];
                 
$FTPstat[$Tline[13]][daily_bytes][$Tline[2]."-".$Tline[1]] += $Tline[7];
        }
 
}
fclose ($handle);

// Prints a simple array. Do some work to print this your way.
echo "<div align=left><pre>";print_r($FTPstat);echo "</pre></div>";
?>


Usage Example




Rate This Script





Search



This Category All Categories