1

I have found this usefull vbscript on the web to automate file download.

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"

Is there a way to force it to parse the url and for example download *.exe file in some web location? like this:

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

file0001.exe  

because I have a URL which has a file which name changes during time. It has .exe extension.

I have both http and ftp protocols enabled over it and ftp has no authentication (free).

4

1 回答 1

0

只有在该站点上启用文件浏览时才有可能,而且这种情况很少发生。您将需要一些列出文件名的 URL 来解析文件名。你最好使用像 wget http://users.ugent.be/~bpuype/wget/这样的工具,它有这样的选项。对于此类操作,vbscript 也不是一个好的选择,如果您从头开始,您最好使用例如 Ruby。

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

于 2012-07-16T21:58:38.813 回答