我需要从FTP服务器获取文件列表,该文件的最后修改日期将晚于我指定的日期(文件是从这个日期开始修改的)。
对于这项任务,哪种方法会更“便宜”?使用cURL库。
发布于 2014-01-30 18:08:25
我的版本:
function since_date ($date, $folder = '')
{
$files = [];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $folder . '/',
CURLOPT_USERPWD => 'user:password',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'LIST -t'
]);
// Convert date to timestamp
$limit = strtotime($date);
// Get files list sorted by last-modification date
if ($ls = curl_exec($curl)) {
foreach (explode("\n", trim($ls, "\n")) as $line) {
// Parse response line to array of values
$line = preg_split('/\s+/', $line, 9);
// Get each file timestamp and compare it with specified date
if ($ts = strtotime(implode(' ', array_slice($line, -4, 3))) >= $limit) {
$files[ end($line) ] = $ts;
} else {
// Got an older files...
break;
}
}
}
curl_close($curl);
return $files;
}https://stackoverflow.com/questions/21439502
复制相似问题