0

我需要监视一些 ftp 服务器以查看文件结构的任何更改,我需要监视的是文件下载了多少次(不确定是否可能),文件是否更改,文件是否被删除,如果ftp服务器仍然存在,

我希望这是我可以运行 server=side 的东西,如果发生上述任何更改,我希望收到一条短信或电子邮件

任何人有任何经验或会推荐一种特定的语言或脚本?

谢谢

4

1 回答 1

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);






        }
?>
于 2012-11-25T07:40:10.717 回答