Command line download large (500+mb) file using vbscript

家住魔仙堡 提交于 2020-05-13 19:15:19

问题


Heart of the problem: I'm trying to download a 650mb file using VBScript. Any file over 500mb fails with the following error...

Error: Not enough storage is available to complete this operation Code: 8007000E

Source: msxml3.dll <-- When using MSXML.XMLHTTP or...

Source: WinHttp.WinHttpRequest <-- when using WinHTTP

I'm using the code from here, both MSXML.XMLHTTP and WinHTTP (not wget). Both scripts I can watch in Task Manager build up to just over 650mb, and then fail with the above error. The scripts work, if I choose smaller files the download occurs just fine.

The lines referenced in the error messages is .Write objHTTP.responseBody for both.

I've found a few other people having this same problem, although there doesn't seem to be a large amount of people trying to download giant files with vbscript... I can't imagine why.

I know it's not a space issue (I have plenty of hard drive space), or a memory issue (I have 4gb, physical memory shows about 70% at peak). I've also tried setting the SetTimeouts option as detailed here when using WinHTTP (I even set them all to -1, infinite timeout), and tried using MSXML.ServerXMLHTTP which allows SetTimeouts as well, both a no-go

Background: I'm trying to write a vbscript to automatically download and install a set of software for a large number of users. Because it's going to be distributed to so many people I would like to do it natively in Windows, since I don't know exactly what other software they may or may not have. This limits my options quite a bit. Powershell policy is set to restricted, so I can't use that on others computers, not without detailing how to reset it for them which defeats the purpose of a script that's supposed to do everything for non-techie users. This pretty much leaves vbscript.

If there is no other way to do this, then my next step is probably going to be to automate the downloading and installation of a smaller file, like wget, and then use that to download the larger one. Again though, I'd like to do this with minimum, native software. It seems like this is something that should be possible, but I can't find a solution.

edit: I can't post more than 2 links as a new user, so you're just going to have to take my word that I've found other people having this issue, but no answers to their threads (here or anywhere else).


回答1:


I cannot reproduce your problem, so I'm unable to provide a solution. However, you may be able to work around it by downloading the file in chunks instead of as a whole:

chunksize = 524288000  '500 MB
url = "..."

Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 'binary

i = 0
Do
  first = i * chunksize
  last  = first + chunksize - 1

  Set req = CreateObject("Msxml2.XMLHttp.6.0")
  req.open "GET", url, False
  req.setRequestHeader "Range", "bytes=" & first & "-" & last
  req.send

  If req.Status = 206 Then stream.Write req.responseBody

  i = i + 1
Loop Until CLng(req.getResponseHeader("Content-Length")) <> chunksize

stream.SaveToFile "C:\path\to\output.file", 2
stream.Close



回答2:


Here I see you have uses HTTP which doesnot support ftp. So my suggestion would be to use Wget. http://www.codeproject.com/Tips/506439/Downloading-files-with-VBScript



来源:https://stackoverflow.com/questions/18445890/command-line-download-large-500mb-file-using-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!