Thanks to both.
Taazz Neither the files to download nor the website which hosts them are under my control. I can't add any files.
engkin Oddly enough, I discovered what you say by chance yesterday - searching the net etc is really a matter of knowing what search terms to use and I finally hit on them. I had been looking at
http://forum.lazarus.freepascal.org/index.php/topic,21337.0.html and noticed that
if http.HTTPMethod('HEAD', fURL)
was used to fetch the length of a file in order to set up a progress bar. That led me on to explore HTTP headers...
I revised my own program to follow the same scheme as the one in that post, giving me a useful progress bar, and added a new bit after the code for obtaining the file length:
if http.HTTPMethod('HEAD', fURL) then
begin
for i := 0 to http.Headers.Count-1 do
begin
s := UpperCase(http.Headers[i]);
if pos('CONTENT-LENGTH:', s) > 0 then
TotalBytes := StrToIntDef(copy(s, pos(':', s) + 1, length(s)), 0);
// Start of new code
if pos('LAST-MODIFIED:', s) > 0 then
LastModDate := copy(s, pos(':', s) + 1, length(s)), 0); //LastModDate is a string
Form1.memProgress.Lines.Append(s); //memProgress is a temporary TMemo which reports what the program is doing as it goes along
// End of new code
end;
http.Headers.Clear;
end;
I'm hoping that the LAST-MODIFIED date will be enough. My program uses an .ini file containing various more or less constant strings like the URL, filenames and paths which might conceivably change - I can edit the ini file a lot faster than rewriting the program. I can store the LAST-MODIFIED date of each zip file as a simple string in the ini file, and only download the zip file again if checking the header as above reveals a non-matching date. IF-MODIFIED-SINCE looks like it would work neatly but with the present state of my knowledge of the subject I'm not sure how I would persuade the server to return the info. And as I am already reading the header for the file length, I might as well stick to the devil I know. Logically I should read LAST-MODIFIED first and bail out if I don't need to go any further.
STOP ! while typing this I have suddenly realised (doh!
) that CONTENT-LENGTH would probably do the job - if the files have been changed at all they are almost certain to have grown. More data is continually being added to the mdb files within the zips, that's precisely why we need to download updates. Sometimes the obvious answer is staring you in the face...
Thank you again.
Caravelle