JSI Tip 8297. Anonymous FTP download script.

Jerold Schulman

July 26, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today


Borrowing from http://www.paulsadowski.com/WSH/getremotebinaryfile.htm, I have scripted FTPVBS.BAT and FTPVBS.VBS to download a binary, or text file, using FTP.

The syntax for using FTPVBS.BAT is:

call FTPVBS URL Folder FileName [OK]

Where URL is the URL of the file you wish to download, Folder is the destination folder where you will store the downloaded file, and FileName is the file name to be stored in Folder.

NOTE: OK is an optional fourth parameter, a call directed environment variable, that will contain a Y if FileName was downloaded, and an N if it was not.

NOTE: FTPVBS.BAT and FTPVBS.VBS must be located in the same folder.

FTPVBS.BAT contains:

@echo offsetlocalif {%3}
{} goto errset URL=%1set fldr=%2#set file=%3set fldr=%fldr:"=%set fldr=%fldr:#=%set fldr="%fldr:#=%"set file="%file:"=%"set ff=%fldr%%file%set ff="%ff:"=%"if exist %ff% del /q %ff%set ftpv="%~DP0FTPVBS.vbs"cscript //NOLOGO %ftpv% %URL% %fldr% %file%if {%4}
{} endlocal&goto :EOFset found=Nif exist %ff% set found=Yendlocal&set %4=%found%goto :EOF:err@echo Syntax: FTPVBS URL Folder FileName [OK]endlocal

FTPVBS.VBS contains:

Dim objArgumentSet objArgument = Wscript.ArgumentsURL=objArgument(0)DestFolder=objArgument(1)ImageFile=objArgument(2)Set xml = CreateObject("Microsoft.XMLHTTP")xml.Open "GET", URL, False, "user", "pass"xml.Sendset oStream = createobject("Adodb.Stream")Const adTypeBinary = 1Const adSaveCreateOverWrite = 2Const adSaveCreateNotExist = 1oStream.type = adTypeBinaryoStream.openoStream.write xml.responseBody' Do not overwrite an existing fileoStream.savetofile DestFolder & ImageFile, adSaveCreateNotExist' Use this form to overwrite a file if it already exists' oStream.savetofile DestFolder & ImageFile, adSaveCreateOverWriteoStream.closeset oStream = nothingSet xml = Nothing



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like