WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinInet
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Check if a File has been Modified on Web Server


Question:

I am trying to write a program to check to see if a webpage has been updated since the I last checked. So far, I can get the info by logging on to the server using:
hSession=ftpOpen(host,userid,pswd,acct,1)
if !IsNumber(hSession)
Message("FTP Open Error",hSession)
exit
endif
ftpChDir(hSession, fromdir)
list=ftpList(hSession,"","ftp.tmp")
files=FileGet("ftp.tmp")

But I was wondering if I am missing something obvious, there must be a way to get this info without having to log on. The method I use takes an age as ftpList takes an age to download all the info for the folder, then I have to parse the info in the 'file' variable... this takes up to 40 seconds to sort out. If anyone has any ideas, I would love to hear them.

Answer:

You might be able to use our wininet Extender to get the webpage headers. Just compare the 'last-modified date found on the server to the one when it was last checked. The code might look something like this:

AddExtender("WWINT44I.DLL")
tophandle=iBegin(0,"","")
datahandle=iUrlOpen(tophandle,"http://www.windowware.com")
headers=iHttpHeaders(datahandle)
iClose(datahandle)
iClose(tophandle)
AskItemList("Headers were",headers,@tab,@sorted,@single)
;Add code to parse out last-modified date
;Store it off somewhere if newer than last stored date.
exit
Or maybe use this freeware utility: http://www.markwell.btinternet.co.uk/webmon/

User Reply:

The freeware one looks good, but I want to be able to personalise each one that goes out so that the bands that are on my website can upload gigs in the correct format, check js files as well as html files and loads of other things. Also I know that it should be possible, and I would love to find out how to do it.
AddExtender("WWINT44I.DLL")
tophandle=iBegin(0,"","")
connecthandle=iHostConnect(tophandle, "www.eluk.co.uk", @HTTP,"","")
datahandle=iHttpInit(connecthandle, "GET", "/pages/chart.js", "",0)
rslt=iHttpOpen(datahandle, "", 0, 0)
xx=iReadData(datahandle, "C:\abc.txt")
headers=iHttpHeaders(datahandle)
iClose(datahandle)
iClose(connecthandle)
iClose(tophandle)
AskItemList("Headers were",headers,@tab,@sorted,@single)
exit
works, but not for files with the extension .shtml and 99% of the html files on the site have that extension!

Answer:

The If-Modified-Since request-header might also be helpful...
AddExtender("WWINT44I.DLL")
tophandle=iBegin(0,"","")
;connecthandle=iHostConnect(tophandle, "www.eluk.co.uk",@HTTP,"", "")
;datahandle=iHttpInit(connecthandle, "GET", "/pages/index.shtml", "",0)
connecthandle=iHostConnect(tophandle, "www.winbatch.com",@HTTP,"", "")
datahandle=iHttpInit(connecthandle, "GET", "/", "",0)
if datahandle==0
   err=iGetLastError()
   Message("Last Error",err)
   iClose(tophandle)
   exit
endif
myheader="If-Modified-Since: Fri, 20 Oct 2006 01:43:31 GMT"
;If the variant has not been modified since a valid If-Modified-Since date, 
; the server SHOULD return a 304 (Not Modified) response.
;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

rslt=iHttpOpen(datahandle, myheader , 0, 0)
if rslt == 304 
   Message("Modified?", StrCat( "File has not been modified since ", myheader)) 
endif

headers=iHttpHeaders(datahandle)

Message("",headers)
iClose(datahandle)
iClose(connecthandle)
iClose(tophandle)
Message("All","Done")
exit
I noticed however that it will not work on the shtm file commented out in the above script. I think this is due to some limitation in the server.
Article ID:   W17377
File Created: 2017:07:28:13:58:45
Last Updated: 2008:04:10:15:08:49