【发布时间】:2015-03-19 14:41:49
【问题描述】:
我被困在一个过程的原子化上,以便在日期明智或今天下载最后修改的文本文件。这是我的代码。
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$contents = ftp_nlist($conn_id, '-rt .');
reset($contents);
function is_txt($file) {
return preg_match('/.*\.txt/', $file) > 0;
}
$filtered = array_filter($contents, is_txt);
// download all files in downloaded directory
while (list($key, $value) = each($filtered )) {
if (ftp_get($conn_id, $dir.'\\downloaded\\'.$value, $value, FTP_BINARY)) {
echo "Successfully written to $value\n";
} else {
echo "There was a problem\n";
}
}
我成功获取文本文件,但没有选择最后修改的文件,filemtime 对我没有帮助,也没有 curl。
【问题讨论】: