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 off setlocal if \{%3\}FTPVBS.VBS contains:\{\} goto err set URL=%1 set fldr=%2# set file=%3 set 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 :EOF set found=N if exist %ff% set found=Y endlocal&set %4=%found% goto :EOF :err @echo Syntax: FTPVBS URL Folder FileName \[OK\] endlocal
Dim objArgument Set objArgument = Wscript.Arguments URL=objArgument(0) DestFolder=objArgument(1) ImageFile=objArgument(2) Set xml = CreateObject("Microsoft.XMLHTTP") xml.Open "GET", URL, False, "user", "pass" xml.Send set oStream = createobject("Adodb.Stream") Const adTypeBinary = 1 Const adSaveCreateOverWrite = 2 Const adSaveCreateNotExist = 1 oStream.type = adTypeBinary oStream.open oStream.write xml.responseBody ' Do not overwrite an existing file oStream.savetofile DestFolder & ImageFile, adSaveCreateNotExist ' Use this form to overwrite a file if it already exists ' oStream.savetofile DestFolder & ImageFile, adSaveCreateOverWrite oStream.close set oStream = nothing Set xml = Nothing
0 comments
Hide comments