VB Script task

February 19, 2011 at 11:41:51
Specs: Windows XP
Hi guys,

I need help to produce vb scripts for 2 tasks. The tasks are very similar to each other. I have no experience with VB Script but was advised this is the best option as I have to avoid d/l any software. I would be grateful if anyone could help me produce the code for the following tasks:

1) Run daily job at 1am to download a file from the internet and save the csv file onto my c:/ drive. The file which I need to download is in a webaddress as follows:

- The webaddress is password protected, so I need to somehow enter the username and password in the vb script.
- the filename changes, so today the webaddress is:
but tomorrow the webaddress will be:

2) the second task is the same as the 1st task, except that the file name does not change, so the webaddress will always be:

Many thanks


See More: VB Script task

Report •

February 20, 2011 at 17:41:23
I don't know if the date is biased off of today, or yesterday, and I don't know how the file is password protected, but this might do what you want. Also, I'm not logging anything; if you're going to use this as an automated task, you should throw in some logging.

Const user = "user"
Const pass = "password"
Const locRoot = "https://78.XXX.XXX.12/log/"
WScript.Quit Main

Function Main
  fileName = FormatDate(Now) & ".csv"
  loc = locRoot & fileName
  GetFile loc, fileName, user, pass
End Function

Function GetFile(sLoc, sFile, sUser, sPass) 'As HTTP status
  'Setup output file
  Set outFile = CreateObject("ADODB.Stream")
  outFile.Type = 2 'Text file

  'Setup HTTP request
  Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
  http.Open "GET", sLoc, False
  http.SetCredentials sUser, sPass, 0

  'Get output
  GetFile = http.Status
  If GetFile = 200 Then
    outFile.WriteText http.ResponseText
    outFile.SaveToFile sFile, 2
  End If
End Function

Function FormatDate(d) 'As String
  FormatDate = DatePart("yyyy", d) & DatePart("m", d) & DatePart("d", d)
End Function

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question