Specifications

echo “Checking file time...<br>”;
if (file_exists($localfile))
{
$localtime = filemtime($localfile);
echo “Local file last updated “;
echo date(“G:i j-M-Y”, $localtime);
echo “<br>”;
}
else
$localtime=0;
$remotetime = ftp_mdtm($conn, $remotefile);
if (!($remotetime >= 0))
{
// This doesn’t mean the file’s not there, server may not support mod time
echo “Can’t access remote file time.<br>”;
$remotetime=$localtime+1; // make sure of an update
}
else
{
echo “Remote file last updated “;
echo date(“G:i j-M-Y”, $remotetime);
echo “<br>”;
}
if (!($remotetime > $localtime))
{
echo “Local copy is up to date.<br>”;
exit;
}
// download file
echo “Getting file from server...<br>”;
$fp = fopen ($localfile, “w”);
if (!$success = ftp_fget($conn, $fp, $remotefile, FTP_BINARY))
{
echo “Error: Could not download file”;
ftp_quit($conn);
exit;
}
fclose($fp);
echo “File downloaded successfully”;
// close connection to host
ftp_quit($conn);
Advanced PHP Techniques
P
ART IV
380
LISTING 17.4 Continued
22 7842 CH17 3/6/01 3:39 PM Page 380