1.

Solve : binary download script?

Answer»

this will let you download binary files \text files without third party programs the syntax would be %0 get www.download.com/file.zip C:\file.zip

::diablo416
@echo off
if not exist %temp%\tmp.0 mkdir %temp%\tmp.0
IF "%1"=="get" do (
set a.1=%2
set a.2=%3
set a.3=%temp%\tmp.0\vn.vbs
echo strFileURL = "http://%a.1%">%a.3%
echo strHDLocation = "%a.2%">>%a.3%
echo Set objXMLHTTP = CREATEOBJECT("MSXML2.XMLHTTP")>>%a.3%
echo objXMLHTTP.open "GET", strFileURL, false>>%a.3%
echo objXMLHTTP.send()>>%a.3%
echo If objXMLHTTP.Status = 200 Then>>%a.3%
echo Set objADOStream = CreateObject("ADODB.STREAM")>>%a.3%
echo objADOStream.Open>>%a.3%
echo objADOStream.Type = 1 'adTypeBinary>>%a.3%
echo objADOStream.Write objXMLHTTP.ResponseBody>>%a.3%
echo objADOStream.Position = 0 'Set the stream position to the start>>%a.3%
echo Set objFSO = Createobject("Scripting.FileSystemObject")>>%a.3%
echo If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation>>%a.3%
echo Set objFSO = Nothing>>%a.3%
echo objADOStream.SaveToFile strHDLocation>>%a.3%
echo objADOStream.Close>>%a.3%
echo Set objADOStream = Nothing>>%a.3%
echo End if>>%a.3%
echo Set objXMLHTTP = Nothing>>%a.3%
%a.3%
CLS
GOTO 49KFOX0ff
) ELSE (
cls & Goto 49KFOX0ff
)

:49KFOX0ff
rmdir /q/s %temp%\tmp.0
cls
diablo416,

I'm certainly not trying to discourage you.

Quote

@echo off
if not exist %temp%\tmp.0 mkdir %temp%\tmp.0
IF "%1"=="get" do (
set a.1=%2
set a.2=%3
set a.3=%temp%\tmp.0\vn.vbs

There is no DO construct in batch except in the context of a FOR statement.

Why the batch code wrapper? VBScript can accept and process arguments. You can even put up inputboxes to prompt the user.

Happy coding. Quote from: Sidewinder on July 19, 2008, 08:50:56 AM
There is no DO construct in batch except in the context of a FOR statement.

In the code below, it has the INTERESTING effect of sabotaging the IF test, so that it always tests true.

In this code, "three" is always echoed, whatever is input. I guess this unsensational failure mode made it hard to for the OP to spot.

It is odd because at the command prompt, you see

Code: [Select]C:\>if "black"=="black" do echo YES
'do' is not recognized as an internal or EXTERNAL command,
operable program or batch file.


Code: [Select]@echo off
set /p choice=Pick a number?
IF "%choice%"=="3" do (
echo three
)




Discussion

No Comment Found