0

I'm writing a wscript with vbscript in Windows 7. The script needs to grab a file from an open ftp server, so I must use MSXML2.XMLHTTP object

The file I am grabbing is being cached in a sub folder of C:\Users\user\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5

The file that is cached has no "expires" value, and trying to set a value using setRequestHeader method doesn't seem to have any effect.

I will self-answer this in case anyone else needs this solution

Steve Wasiura
  • 768
  • 1
  • 8
  • 19

1 Answers1

0

this code snippet shows how to delete the cached files from the folder used by MSXML2.XMLHTTP, using the concept of the downloaded files will have the extension ".csv"

<job>
<script language="vbscript">

' use XMLHTTP to grab content from a URL

CMEURL = "ftp://ftp.cmegroup.com/pub/settle/nymex_future.csv"

' the downloaded files are being stored in a subfolder of this folder
filedownloadcachelocation =  "C:\Users\user\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5"

' delete the file before requesting a download

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fileresults 

Dim Directory
Set Directory = fso.GetFolder(filedownloadcachelocation)
Dim subfolders
Set subfolders = Directory.SubFolders
For Each Folder In subfolders
    For Each FileName In Folder.Files
        ' only react if filename extension is csv
        If InStr(FileName , ".csv") Then
            fileresults = fileresults & FileName.Path & vbLf 

            ' delete the file
            If fso.FileExists(FileName.Path) Then
                'WScript.Echo "deleting file " & FileName.Path
                fso.DeleteFile FileName.Path
            End If


        End If ' csv ext
    Next ' each file in folder
Next ' each folder in Content.IE5

WScript.Echo "files found that were deleted = " & VbLf & fileresults

' now continue with downloading the file using XMLHTTP
Steve Wasiura
  • 768
  • 1
  • 8
  • 19