The previous article was about uploading files using VBA and IE. But what to do if you have only VBS (in WSH, IE or ASP)? VBS does not have functions which can work with binary data so you cannot read contents of a file from disk.
But you can use several objects which lets you work with binary data (one of them is also on this site, ScriptUtilities). ADODB, which is included in a free microsoft data access sofware (MDAC), enables the work with binary data also.
You can use ScriptUtils.ASPForm to accept uploaded files in ASP. ScriptUtils.ASPForm contains hi-performance, low resources consumption algorithm which can accept up to 2GB of data.
1. There are some steps to upload file using http and multipart/form-data document. First of all we have to read file from a disk. We can use Scripting.FileSystemObject to read text data, or ADODB.Stream to read any file. The GetFile function does the work using ADODB.Stream.
2. The second task we need to complette is a build of multipart/form-data document. The document contains from several fields separated by boundary. Each of the fields has its own header, which contains information about field name, file name and content-type of the source file. ADO Recordset object has a great method AppendChunk, which lets you join parts of multipart/form-data document (open boundary + headers + file contents + close boundary). You can see the code in BuildFormData function.
3. Last task is send the multipart/form-data document as a post request to server with multipart/form-data Content-Type header. We can use at least two object to send POST request - XMLHttp or InternetExplorer. This script uses Navigate method of InternetExplorer.Application object. You can see the code in IEPostBinaryRequest function
Next vbs code is complette vbs file which lets you upload any file from client computer to server using http protocol and multipart/form-data form (form with input type=file). You can copy the code to file named fupload.vbs. Then you can use:
use [cscript|wscript] fupload.vbs file url [fieldname] file ... Local file to upload url ... URL which can accept uploaded data fieldname ... Name of the source form field.UploadFile function can be also used in any other vbs envinronment, for example in ASP application, WSH, or in HTA application. I used Internet Explorer to send binary data (Function IEPostBinaryRequest), because Internet Explorer is installed on each computer with Windows. But remember, that using of the object is NOT ideal. See Post binary data to URL from WSH/ASP/VBA/VBS article. The article contains some better alternative objects, which lets you send binary data to remote script.
for 'Automatic file upload using IE+ADO without user interaction - VBSscript' articleDownload multiple files in one http requestThis article shows a way to download multiple files in one http request. It let's you send an HTML page along with image preview, prepare more files for download and send the files as one data stream. One request, one authentication per multiple files.
Post binary data to URL from WSH/ASP/VBA/VBScript.Two methods to POST binary or string data to external URL and read results sent from a script on the URL.
Automated file upload using IE, without user interaction - VBALets you send file from a client to www server over http connection using IE. The file is sent as a result of type=file form field.
Copyright and use this code
The source code on this page and other samples at http://www.motobit.com/tips/ are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
2. Link this sample from you page.
<A Href="http://www.motobit.com/tips/detpg_uploadvbsie/" Title="Lets you upload file from a client to www server over http connection using vbs, IE and ADODB. The file is sent as a result of type=file form field encoded multipart/form-data." >Automatic file upload using IE+ADO without user interaction - VBSscript</A>
© 1996 - 2012 Antonin Foller, Motobit Software | About, Contacts | e-mail: email@example.com
Partner sites: Search Czech Last minute Zajezdy Obsah na mobil Hry na mobil Java Hry Print-shop Affiliate programy
Kurzy: Akcie | Urad prace | Zakony | Zlato | Firmy | Dane
|IISTracer - IIS ISAPI real-time monitor IISTracer is a real-time monitoring tool for Microsoft IIS, which will show/log you what is happenning on IIS server right now. It let's you reveal problems with long-running scripts (.asp, .cgi, cfm...), hang-up states and low resource situations and lets you stop long-running requests (uploads/downloads).||ActiveX User account Manager - Set of simple objects for creating, deleting, and managing user accounts, groups, servers and domains in the Windows NT environment.|
|Active log file - Hi-performance text file logging for ASP/VBS/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.||ActiveX windows registry editor - Intuitive, easy to use COM interface to windows registry. Set of classes to read/enumerate/modify windows registry keys and values from ASP, VBS and T-SQL.|
|ActiveX/ASP Multi Dictionary object - Free-threaded hi-speed dictionary algorithm with unique/nonunique keys (map/multimap). Connect to another dictionary object in the same process. Lock and Unlock methods to synchronize tasks (application scope). Share ASP Application/Session objects.||Export DBF/MDB from ASP - Conversion from recordset to MDB/DBF. Direct binary output of MDB or DBF files from ASP pages with one row of code.|
|Pure-ASP upload - lets you upload files using Pure ASP VBS code (using multipart/form-data and input type=file).||ByteArray - Works with safearray binary data (VT_UI1 | VT_ARRAY) - save/restore binary data from disk, find, work with code pages, convert to string/hexstring(SQL).|
|WebChecker - Checks http, https, ftp and gopher internet connections in regular intervals. Lets you monitor web site functionality (uptime). Enables restart or notification on problems.||HTTPLog ISAPI filter - Lets you log incomming/outgoing http header and document data to separate files. Monitor of IIS service input/output.|