Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

July 27, 2004 12:00 AM

JSI Tip 8297. Anonymous FTP download script.

Windows IT Pro
InstantDoc ID #81417
Rating: (0)


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}

{} 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
FTPVBS.VBS contains:
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



Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.