VBScript to upload file to website (ADODB.Stream)

Scripting List Solutions: VBScript to upload file to website


srcFolder = “\\server\share\
strUserID = “MyID”
strPassword = “APasswordGoesHere”
strURL = “https://www.theuploadwebsite.com/puthere/

Set HTTP = WScript.CreateObject(“Microsoft.XMLHTTP”)
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set folder = fso.getfolder(srcFolder)

For Each File in Folder.Files
If fso.GetExtensionName(File)=”TXT” Then
Set objStream = CreateObject(“ADODB.Stream”)
objStream.Type = 1
objStream.Open
objStream.LoadFromFile(srcFolder & fso.GetFileName(File))

    HTTP.open “PUT”, strURL & fso.GetFileName(File), False, strUserID, strPassword
WScript.Echo “Now uploading file ” & fso.GetFileName(File)


HTTP.send objStream.Read

    WScript.Echo “Uploading complete for file ” & fso.GetFileName(File)
fso.DeleteFile(File)
End If
Next
WScript.Echo “All files uploaded.”

Set HTTP = Nothing


Filed under: ,

This entry was posted in Code Snippets. Bookmark the permalink.

2 Responses to VBScript to upload file to website (ADODB.Stream)

  1. tuchka says:

    Would that try to upload a whole file in one go or would it stream it, allowing upload of very large files?

  2. Pavan says:

    I am getting runtime error 76 path not found on the line
    Set Folder = fso.getfolder(srcFolder)
    I used srcFolder = “\\ROWDY\test”
    test is a shared folder on my local machine in which text files are stored.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s