2012-10-27 192 views
0

我需要監控一些ftp服務器的文件結構的任何變化,我需要監控的是文件下載的次數(如果可能,不確定),如果文件被更改或沒有更改,文件被刪除與否,如果FTP服務器仍然存在,FTP服務器監控

我想這是一件我可以運行服務器=側,想一個短信或電子郵件,如果上述任何變化發生

任何一個人有任何經驗或會推薦一種特定的語言或腳本?

感謝

+0

僅供參考,我不想安裝FTP服務器,我只是想要的東西來幫助我監視其他ftp服務器通過定期登錄 –

+0

serverfault.com –

回答

0

爲PHP我用這個簡單的腳本

<

? 
ini_set('auto_detect_line_endings', true); 
error_reporting(E_ALL); 

set_time_limit(0); 
ini_set('show_errors', 1); 
$file = "ftpfile.txt"; 
$handle = fopen($file, "r"); 

$date = new DateTime(); 
$date = $date->setTimezone(new DateTimeZone('America/New_York')); 
$date = $date->format('U = Y-m-d H:i:s') . "\n"; 

if(!filesize($file)>0) { 
     echo "File is empty!"; 
    } 
    else { 
    while (($ftpservers = fgets($handle)) !== false) { 

     //echo $ftpservers. "<br>"; 
     $ftpserver= explode ("<br>", $ftpservers); 
     //$pattern = "//"; 
     //preg_match ($pattern, $ftpservers, $output); 

     foreach ($ftpserver as $ftpserverurl) { 
$ch = curl_init();     //this part we set up curl 
curl_setopt($ch, CURLOPT_URL,$ftpserverurl); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,40); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_exec($ch); 

if(curl_errno($ch)) 
{ 
sleep(2); //add sleep in order to not overload hosting server 
$echooutput = $date. 'Curl error: ' . curl_error($ch). 'Server Malfunctioned:' .$ftpserverurl; 
error_log("$echooutput", 3, "ftperrors.log"); //write error to log 
error_log("$echooutput", 1, "your email address"); //email alert 
curl_close ($ch); 


} 
else 
{ 
error_log("$date curl operation is sucessful \n", 3, "curl.log"); //keep track of successful connections for pattern anaylsis 
curl_close ($ch); 

} 

     } 

    } 
    //if (!feof($handle)) { 
     //echo "Error: unexpected fgets() fail\n"; 
    //} 
    fclose($handle); 






     } 
?>