簡體   English   中英

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

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

我需要從FTP服務器獲取文件列表,該文件的最后修改日期將晚於我的特定日期(從該日期開始修改的文件)。

哪種方法可以“便宜”完成此任務? 為PHP使用cURL庫。

我的版本:

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