get date last modified

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a VBScript as follows:

Dim xmlHTTP : Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
Dim adoStream : Set adoStream = CreateObject("adodb.stream")

Const bGetAsAsync = False ' wait for response
Const adTypeBinary = 1 ' ado typelib constants
Const adModeReadWrite = 3
Const adSaveCreateOverwrite = 2
Const ForReading = 1, ForWriting = 2, ForAppending = 8

sSource = "https://website.com/download/companyname.20060101.zip"
sSaveName = "companyname.20060101.zip"
sSavePath = "C:\temp\dir\"

xmlHTTP.Open "GET", sSource, bGetAsAsync, "username", "pass"
xmlHTTP.Send
'
With adoStream ' write the file to local disk
..Type = adTypeBinary ' as BINARY
..Mode = adModeReadWrite
..Open
..Write xmlHTTP.responseBody ' write data (as binary)
..SaveToFile sSavePath & sSaveName, adSaveCreateOverwrite
..Close
End With

This is great when specifying an individual file, but I need to grab the
last modified file each morning. The file will take on the format of
companyname.20060101.zip Do I need a GET statement or something?
 
I'm not sure I'm understanding you correctly. Are you asking how you can dynamically generate
sScource and sSaveName to use the current date?
If that's the case, you can just use the following to create the string:
DateTime.Now.Year
DateTime.Now.Month
DateTime.Now.Day

If you just need the current file from the webserver and the date will not always be the current
date, you can create an asp page on the webserver that would look in the directory, and use
File.GetLastWriteTime(fileloc)
The page could then return the value of sSaveName. Your program would then need to look at that
page first. Read the results and set it into sSaveName and sSource.

Did I get the question right?

===Tome
http://www.pcdotcom.com
 
I believe you're on the right track, but I'm a VBScript newbie. What would
the code look like incorporated into what I already have?
 
The first suggestion, but I get an error:

Line 4 Character 8 Expected end of statement. I've modified the code to
look like this:


Dim xmlHTTP : Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
Dim adoStream : Set adoStream = CreateObject("adodb.stream")
Dim d1 As DateTime = DateTime.Now


Const bGetAsAsync = False ' wait for response
Const adTypeBinary = 1 ' ado typelib constants
Const adModeReadWrite = 3
Const adSaveCreateOverwrite = 2
Const ForReading = 1, ForWriting = 2, ForAppending = 8

sSource = "https://website.com/download/" + sSavename
sSaveName = "companyname." + + d1.ToString("yyyyMMdd") + ".zip"
sSavePath = "\\servername\Downloads\"

xmlHTTP.Open "GET", sSource, bGetAsAsync, "ID", "PW"
xmlHTTP.Send

'msgbox MONTH(now()) & "%" & DAY(now())
'IF InStr (targetfile, ".zip") THEN 'AND InStr (targetfile, YEAR(now()) &
RIGHT("0"& MONTH(now()),2)& DAY(now())) THEN
'With iMsg
'Set .Configuration = iConf
'End If

With adoStream ' write the file to local disk
..Type = adTypeBinary ' as BINARY
..Mode = adModeReadWrite
..Open
..Write xmlHTTP.responseBody ' write data (as binary)
..SaveToFile sSavePath & adSaveCreateOverwrite
..Close
End With
 
Because it's not all of your code I don't know what's causing that error. I would look at line 4 in
your code.

I did notice the following though:

1) The following lines need to be placed in this order. You have them backwards.
sSaveName = "companyname." + d1.ToString("yyyyMMdd") + ".zip"
sSource = "https://website.com/download/" + sSavename

2) You have two plusses in the following line. It should look like the line above:
sSaveName = "companyname." + + d1.ToString("yyyyMMdd") + ".zip"

Other than that, you'll have to debug your error... if you copy the below code into the load event
of a new windows program you will see that it produces the desired results:

Dim d1 As DateTime = DateTime.Now
Dim sSource As String
Dim sSaveName As String

sSaveName = "companyname." + d1.ToString("yyyyMMdd") + ".zip"
sSource = "https://website.com/download/" + sSaveName

MessageBox.Show(sSaveName)
MessageBox.Show(sSource)

---Tome
http://www.pcdotcom.com
 
This still doesn't work. It gets held up on the "As" keyword. Expects and
end of statement. I can't believe its this difficult to download the last
modified dat file from a HTTPS:// website to a network drive. I've Googled
this and have come up with nothing so far.
 
Back
Top