Here's an issue I'm struggling with. I need to FTP into a remote sever via PHP and then grab all the latest images that are in a directory there. I've written a script that will go through all the images in a directory and download them to a directory on the local server. It will compare filenames at the moment and if the file already exists on the local server, it doesn't bother downloading it again to save bandwidth (this script runs ever hour on Cron and there's several hundred images in there so it's an important consideration).
HOWEVER, it looks like I'm going to have to be a bit more clever than just checking filenames, as images on the remote server are changing but keeping the same filenames. Therefore, an image gets updated on the remote server but not on my local one. Only way I can think of doing this is to check the date of the files on the remote server, and if it has changed since the last sync, the file needs to be downloaded. Something like;
Code: Select all
$ftp=ftp_connect($ftp_ip);
ftp_login($ftp,$ftp_username,$ftp_password);
// thumbails images
ftp_chdir($ftp, "images");
$contents = ftp_nlist($ftp, ".");
$num_of_images=count($contents);
for ($i=0; $i<=$num_of_images; $i++)
{
// check date of remote file
// check date we have stored for this file on the last sync
// if remote_date!=local_date, get file and store remote date again
}