Discussion:
Download files - VBScript
(too old to reply)
GS
2014-03-24 17:09:38 UTC
Permalink
This is what I came up with for downloading multiple files after
looking at various examples. This uses Microsoft.XMLHTTP and
Adodb.Stream as opposed to Scripting.FileSystemObject!

<Script>
Option Explicit

' Downloads listed files from a specified URL folder,
' to a pre-existing folder of a specified path.

Dim vF, oAdoStream, oXmlHttp
Set oXmlHttp = createobject("Microsoft.XMLHTTP")
Set oAdoStream = createobject("Adodb.Stream")

Const DnldURL = "http://www.mywebsite.com/downloads/"
Const DnldFLDR = "C:\MyMainFolder\MySubfolder\"
Const appFILES = "File1,File2,File3,File4"

'Download Deps
For Each vF In Split(appFILES, ",")
oXmlHttp.Open "GET", DnldURL & vF, False
oXmlHttp.Send

With oAdoStream
.Type = 1 '//binary
.Open: .Write oXmlHttp.responseBody
.SaveToFile DnldFLDR & vF, 2 '//overwrite
.Close
End With '//oAdoStream
Next '//vF

'Cleanup
Set oXmlHttp = Nothing: Set oAdoStream = Nothing
</Script>

Does anyone have an opinion as to whether Scripting.FileSystemObject
might be better, and/or pros/cons of either?
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2014-03-24 23:29:40 UTC
Permalink
| Does anyone have an opinion as to whether Scripting.FileSystemObject
| might be better, and/or pros/cons of either?
|

If you're downloading a byte stream FSO is
very tricky to deal with. It's designed to deal
with text, and treats the bytes according to
the local codepage. On a multi-byte system
(Japanese, Korean, etc) it would be a nightmare.
On a Western system it can be used but requires
special handling. As long as you don't have to
use it for this you're better off not doing so.
GS
2014-03-25 01:42:21 UTC
Permalink
Post by Mayayana
Post by GS
Does anyone have an opinion as to whether Scripting.FileSystemObject
might be better, and/or pros/cons of either?
If you're downloading a byte stream FSO is
very tricky to deal with. It's designed to deal
with text, and treats the bytes according to
the local codepage. On a multi-byte system
(Japanese, Korean, etc) it would be a nightmare.
On a Western system it can be used but requires
special handling. As long as you don't have to
use it for this you're better off not doing so.
Thank you for confirming my suspicions. I actually needed this to
download dependency ActiveX components for one of my VB6 apps. This
reduced the installer size from 1.6mb to 308kb by not packaging these
controls inside.

As I posted yesterday, I already made a small VB6.exe that uses the API
function *URLDownloadToFile* sample code, which works equally as well
as this vbscript does. The only difference using one over the other is,
using exe the installer has to place in temp folder, run it, then
remove it; using the vbscript the installer just runs it internally. If
there were lots of folders to download from it could be speedier to use
a script for each folder, or a nested loop to iterate each
folder:fileset in a single script. The latter would be more
maintenance, though, if installation configurations are used where some
folders are either included or omitted. Having this flexibility sits
well with me!<g>
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Loading...