Jump to content

Command-line HTTP downloader for Win2k8r2


kai4785

Recommended Posts

I know I'm being picky here, but I would prefer to not have to download/install 'wget' or 'curl' win32 binaries. I'm looking for a tool built into Windows Server 2008 R2. Is there such a thing? Even a 10 line vb script or something would be preferable.

Link to comment
Share on other sites


Sort of - bitsadmin.exe can do this, but it'll require you reading the documentation and monitoring the whole download via the exe. However, as of Vista, it ships with the OS if the BITS feature is installed (and I believe that is the default as well - my Server 2008 R2 machines all have BITS installed, and they're stock retail installs for repros that I rebuild every 15 days or so). Basically, you create a "job", add a file (or files) to a job, then resume and monitor it - when the download is/are complete, you have to "complete" the job.

Link to comment
Share on other sites

Wow, I'm kinda stuck between being surprised and not surprised. Bitsadmin is another example of a tool that's over kill for my needs. Maybe it is in my best interest to simply shove a wget executable into my WinPE image.

Thanks.

Link to comment
Share on other sites

bitsadmin is a tool that's not really designed to do what you want to do - it's more for large downloads over network connections it isn't supposed to saturate (hence why bits can be throttled back by pretty much any other network traffic). It can be used for such a thing, but wasn't designed to be used this way. Honestly, putting the wget binary onto a WinPE or Windows box if you plan on using it a lot is probably a lot better use if you want an easy way to do this and don't need the throttling bits can do (and it doesn't seem that you do).

Link to comment
Share on other sites

So it looks like I need a 64bit version of wget, since syswow64 is missing from WinPE, and I need 64bit WinPE to do 64bit Installs. I can't find any on google. Do I need to go compile my own?

Link to comment
Share on other sites

This VBscript can download HTTP files without any 3rd party tools. If you ask nicely, maybe someone would modify this to work with an external csv or text file. Then it could download all your files, and you'd be able to edit your list with notepad.

See robvanderwoude.com for greater detail

HTTPDownload "http://download.microsoft.com/download/4/A/A/4AA524C6-239D-47FF-860B-5B397199CBF8/windows-kb890830-v3.6.exe", "C:\"

Sub HTTPDownload( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832

' Standard housekeeping
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists( myPath ) Then
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
WScript.Echo "ERROR: Target folder not found."
Exit Sub
End If

' Create or open the target file
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )

' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send

' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next

' Close the target file
objFile.Close( )
End Sub

Edited by MrJinje
Link to comment
Share on other sites

So it looks like I need a 64bit version of wget, since syswow64 is missing from WinPE, and I need 64bit WinPE to do 64bit Installs. I can't find any on google. Do I need to go compile my own?

Technically an x86 WinPE should be able to apply an x64 WIM file without issue, although if you're calling setup.exe to install Windows from media then yes, you'll need an x64 PE.

Link to comment
Share on other sites

  • 1 month later...

I think this is exactly what I'll need. If I can get this integrated the way that I think I want it to, you've just made me a very happy camper.

Leave it to me to complain for weeks about how certain things can't be done, and then walk away for a month only minutes before a solution is presented. Curse my luck!

This VBscript can download HTTP files without any 3rd party tools. If you ask nicely, maybe someone would modify this to work with an external csv or text file. Then it could download all your files, and you'd be able to edit your list with notepad.

See robvanderwoude.com for greater detail

HTTPDownload "http://download.microsoft.com/download/4/A/A/4AA524C6-239D-47FF-860B-5B397199CBF8/windows-kb890830-v3.6.exe", "C:\"

Sub HTTPDownload( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832

' Standard housekeeping
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists( myPath ) Then
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
WScript.Echo "ERROR: Target folder not found."
Exit Sub
End If

' Create or open the target file
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )

' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send

' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next

' Close the target file
objFile.Close( )
End Sub

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...