简体   繁体   English

自特定日期以来如何获取FTP服务器中的文件列表(命令或cURL php)

[英]How to get list of files in FTP-server since specific date (command or cURL php)

I'm need to get list of files from FTP-server which last-modified date will be later than my specific date (files which was modified from this date). 我需要从FTP服务器获取文件列表,该文件的最后修改日期将晚于我的特定日期(从该日期开始修改的文件)。

Which way will be "cheaper" for this task? 哪种方法可以“便宜”完成此任务? Using cURL library for PHP. 为PHP使用cURL库。

My version: 我的版本:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM