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