File vbScript按扩展名自动下载文件

File vbScript按扩展名自动下载文件,file,vbscript,download,file-extension,File,Vbscript,Download,File Extension,我发现这个有用的vbscript可以自动下载文件 function download(sFileURL, sLocation) 'create xmlhttp object Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") 'get the remote file objXMLHTTP.open "GET", sFileURL, false 'send the request objXMLHTTP.send() 'wait until the

我发现这个有用的vbscript可以自动下载文件

function download(sFileURL, sLocation)

'create xmlhttp object
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

'get the remote file
objXMLHTTP.open "GET", sFileURL, false

'send the request
objXMLHTTP.send()

'wait until the data has downloaded successfully
do until objXMLHTTP.Status = 200 :  wscript.sleep(1000) :  loop

'if the data has downloaded sucessfully
If objXMLHTTP.Status = 200 Then

        'create binary stream object
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open

        'adTypeBinary
    objADOStream.Type = 1
    objADOStream.Write objXMLHTTP.ResponseBody

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

        'create file system object to allow the script to check for an existing file
        Set objFSO = Createobject("Scripting.FileSystemObject")

        'check if the file exists, if it exists then delete it
    If objFSO.Fileexists(sLocation) Then objFSO.DeleteFile sLocation

        'destroy file system object
    Set objFSO = Nothing

        'save the ado stream to a file
    objADOStream.SaveToFile sLocation

        'close the ado stream
    objADOStream.Close

    'destroy the ado stream object
    Set objADOStream = Nothing

'end object downloaded successfully
End if

'destroy xml http object
Set objXMLHTTP = Nothing

End function

download "http://remote-location-of-file", "C:\name-of-file-and-extension"
有没有办法强迫它解析url,例如在某个web位置下载*.exe文件?像这样:

URL:  http://examplesite.com/files/

file0001.exe  
因为我有一个URL,其中有一个文件名会随着时间的推移而改变。它有.exe扩展名


我在上面启用了http和ftp协议,ftp没有身份验证(免费)

只有在该站点上启用文件浏览时才有可能实现,但这种情况很少发生。您将需要一些列出文件名的URL来解析文件名。您最好使用wget这样的工具,它有这样的选项。另外,vbscript对于这样的操作不是一个好的选择,如果你从零开始,你最好使用例如Ruby

如果你发布有问题的URL,也许我可以进一步帮助你