我需要修改此脚本以仅检索具有昨天日期的文件。这是我所拥有的:
<?php
$username = 'XXXXXX';
$password = 'XXXXXX';
$ftp_server = 'data.mywebsite.com';
$conn = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
if(ftp_login($conn, $username, $password))
{
echo 'Logged in';
}
else
{
echo 'FTP Error:Could not log in to '.$ftp_server;
exit();
}
ftp_pasv ($conn, true);
if (ftp_chdir($conn, "../Photos/Hi-res")) {
echo "Current FTP directory is now: " . ftp_pwd($conn) . "\n";
} else {
echo "Couldn't change to Photos directory\n";
}
$list = ftp_nlist($conn, '.');
function is_img($file) {
if(preg_match('/.*\.png/', $file))
{
return preg_match('/.*\.png/', $file) > 0;
}
if(preg_match('/.*\.jpg/', $file))
{
return preg_match('/.*\.jpg/', $file) > 0;
}
if(preg_match('/.*\.gif/', $file))
{
return preg_match('/.*\.gif/', $file) > 0;
}
}
$filtered = array_filter($list, is_img);
foreach($filtered as $img) {
if (ftp_get($conn, $img, $img, FTP_BINARY)) {
echo "Successfully written to $img\n";
} else {
echo "There was a problem\n";
}
}
ftp_close($conn);
当我运行脚本时,它会抓取我服务器上不存在的所有文件,这不是我想要的。我只想让它抓取所有具有昨天日期的文件。谢谢