如何防止来自MSXML2.XMLHTTP,vbscript的缓存响应

时间:2018-04-20 15:36:36

标签: vbscript windows-7 cache-control msxml2

我正在Windows 7中用vbscript编写一个wscript。 脚本需要从打开的ftp服务器获取文件,所以我必须使用MSXML2.XMLHTTP对象

我抓取的文件正在缓存在子文件夹中 C:\ Users \ user \ AppData \ Local \ Microsoft \ Windows \ Temporary Internet Files \ Content.IE5

缓存的文件没有“expires”值,尝试使用setRequestHeader方法设置值似乎没有任何效果。

如果其他人需要此解决方案,我会自行回答这个问题

1 个答案:

答案 0 :(得分:0)

此代码段显示如何从MSXML2.XMLHTTP使用的文件夹中删除缓存文件,使用下载文件的概念将扩展名为“.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
相关问题