1

I need to download latest file from website without using wget or any external utility. I found following vbscript on stack overflow itself (didnt know link, because I have cleared the cache and history)

' Set your settings
    strFileURL = "http://somewebsitehere.com/somefile"
    strHDLocation = "D:\somepath\"

' Fetch the file
    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

    objXMLHTTP.open "GET", strFileURL, false
    objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary

objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0
'Set the stream position to the start

Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing

objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if

Set objXMLHTTP = Nothing

However after using this script, I found it did work correctly for first few trials but later download same file from cache instead of downloading the fresh file from net. I get same file from C:\Users\username\AppData\Local\Microsoft\Windows\INetCache\IE\0XQSU247. I need to clear the INETCache and then re run the script to get the fresh file. So how should this script be modified so it gets latest updated file from web server instead of getting files from cache. This question might be lame, but I have no knowledge of vbscript.

ashu
  • 1,197
  • 2
  • 14
  • 30
  • 1
    possible duplicate of [How to make Microsoft XmlHttpRequest honor cache control directive](http://stackoverflow.com/questions/5235464/how-to-make-microsoft-xmlhttprequest-honor-cache-control-directive) – MC ND Nov 02 '14 at 14:31
  • Since I dont have good knowledge of xml or vbs, i was unable to search for related post in forum. Apologies. What I see from your link is two possible ways: request.setRequestHeader("cache-control", "private"); or using serverxmlhttprequest. Both solutions are not working in one or the other scenarios. Which one shall I prefer in my case?? I simply need to sync the file across multiple systems and so just want to get latest copy of whatever file is present in server... – ashu Nov 02 '14 at 14:59

0 Answers0