Link to home
Start Free TrialLog in
Avatar of eteran
eteranFlag for United States of America

asked on

VBS with a URL

I have this in a vbs file I created. The point is to for this to download the .txt file. But for some reason it prints the txt file on a explorer window. Is there a way I can force it to download. Please help

Dim ie, strURL, x
strURL = "ftp://gdhse:tygfdtk9@gthe.net/idx/idx_dn/sdf.txt"
Set ie = WScript.CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate strURL
Do while ie.busy: x=x+300000000000: loop

Avatar of basicinstinct
basicinstinct
Flag of Australia image

hi, that's what "InternetExplorer.Application" is for, it creates an instance of a web browser that you can control thru script...

if it was me i'd be bypassing the browser all together and try to work out how to make an http get request from vbscript... probably need to download a third party vbscript library for it...  a quick google search brought up these promising results:

http://www.activexperts.com/activsocket/howto/http/vbscript/
http://www.example-code.com/vbscript/http_get.asp
You can download the file with Internet Explorer but I suggest you don't use it. See this page:

I suggest you use the following script to download a file:

Dim strURL, strTargetPath, objXH, objBS

strURL = "http://localhost/info.txt"
strTargetPath = "C:\info.txt"

Set objXH = CreateObject("Microsoft.XMLHTTP")
objXH.Open "GET", strURL, False
objXH.Send

objResponse = objXH.ResponseBody

Set objBS = CreateObject("ADODB.Stream")
objBS.Type = 1 'Binary
objBS.Open
objBS.Write objResponse
objBS.SaveToFile strTargetPath, 2 '1=adSaveCreateNotExist, 2=adSaveCreateOverWrite
objBS.Close

Set objBS = Nothing
Set objXH = Nothing
Avatar of eteran

ASKER

But I am not programming anything. I need to down load some data daily from a server that is saved in .txt format. Is there a way for me to twick my explorer window not to view the .txt file but to download.
Try the code I posted. It's similar to your code but works exactly like you want it- downloads a file.

All you need to do is put the code in a text file, change the 2nd & 3rd line to your URL and where you want it to save the file and then save it as a VBS file.

If you wanted, you could also add a scheduled task that runs this daily.
>>But I am not programming anything.

This sure looks like programming to me:

Dim ie, strURL, x
strURL = "ftp://gdhse:tygfdtk9@gthe.net/idx/idx_dn/sdf.txt"
Set ie = WScript.CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate strURL
Do while ie.busy: x=x+300000000000: loop


Why don't you use FTP instead, download a scriptable client like WinSCP (http://winscp.net/) and write a script that downloads your file every day.
Avatar of eteran

ASKER

How would I go about building a script for that any idea. I have not programmed in that before, can you post a sample code.
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial