I am using PHP Curl to grab files from a url. Currently the file names are hard coded and I am trying to make it so that it downloads all the log files in a specific directory. Any point in the right direction would be nice. Thank you.
Please note that I have "Read" wright to a directory, I don't have FTP access or anything else.
Server_url : http://192.168.2.45/logfiles/
Server : server1
Files in that directory : 140512 ... 150316.log and growing
<?php
$server_url = $_GET['server_url'];
$server = $_GET['server'];
//This needs to be changed to get all files
for($i = 140512; $i <= 150316; $i++) {
$id = base64_encode($i);
$file_name = $server_url.$i.'.log';
curl_setopt($ch,CURLOPT_URL,$file_name);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return data as string
// disable peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// disable host verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// spoof a real browser client string
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
$output = curl_exec($ch); // capture data into $output variable
if(!dir('sites/'.$server.'_LOGS')){
mkdir('sites/'.$server.'_LOGS');
}
if( $output != false){
file_put_contents('sites/'.$server.'_LOGS'.'/u_ex' . base64_decode($id) . '.log', $output );
}
curl_close($ch);
}
?>