Your task can be easily scripted using Windows Script Host languages -- VBScript or JScript.
To download a file from Internet, you can use the XMLHTTP
object to request the file contents from the server and then use the ADO Stream object to save it to a file on the disk.
As for the timestamp, the problem is that neither VBScript nor JScript have built-in functions that would format the date in the format you need, so you will have to write the code for doing this yourself. For example, you could split the date into parts, pad them if necessary and concatenate them back together. Or you could use the WMI SWbemDateTime
object that uses the yyyymmddHHMMSS.mmmmmmsUUU
date format, and simply extract the yyyymmddHHMMSS
part from it.
Anyway, here's a sample script (in VBScript) that illustrates the idea. I hard-coded the original file name in the strFile
variable, because I was too lazy to extract in from the URL (and also in case the URL doesn't specify the file name, like in http://www.google.com).
Dim strURL, strFile, strFolder, oFSO, dt, oHTTP, oStream
strURL = "http://www.google.com/intl/en_ALL/images/logo.gif" ''# The URL to download
strFile = "logo.jpg" ''# The file name
strFolder = "C:\Storage" ''# The folder where to save the files
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
''# If the download folder doesn't exist, create it
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(strFolder) Then
oFSO.CreateFolder strFolder
End If
''# Generate the file name containing the date-time stamp
Set dt = CreateObject("WbemScripting.SWbemDateTime")
dt.SetVarDate Now
strFile = oFSO.GetBaseName(strFile) & "-" & Split(dt.Value, ".")(0) & "." & oFSO.GetExtensionName(strFile)
''# Download the URL
Set oHTTP = CreateObject("MSXML2.XMLHTTP")
oHTTP.open "GET", strURL, False
oHTTP.send
If oHTTP.Status <> 200 Then
''# Failed to download the file
WScript.Echo "Error " & oHTTP.Status & ": " & oHTTP.StatusText
Else
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = adTypeBinary
oStream.Open
''# Write the downloaded byte stream to the target file
oStream.Write oHTTP.ResponseBody
oStream.SaveToFile oFSO.BuildPath(strFolder, strFile), adSaveCreateOverWrite
oStream.Close
End If
Feel free to ask if you need more explanation.