DTS ActiveX - Download file from an url(http://..)
Can anyone help me to automate the file download from a http url.
I hv set of files located in "http://remotesrvr:8080/datafiles/eachday/" with hyperlinks on each file. Manually I hv to access this url, right click the filename and download it to my local desk. We want to automate the process, by giving the source location as "http://remotesrvr:8080/datafiles/eachday/data_20080407.txt" and the destination cld be "c:\datafile\today\data_20080407.txt".
As it is not a FTP location or can't be mapped thru' network, finding it difficult to do it using DTS ActiveX script. I tried it by doing SCREENSCRAPPING, but it gives "out of memory" exception when the file is huge to read.
Ref the code snippet below,
'************************************************* ********************
' Visual Basic ActiveX Script
'************************************************* ********************
Dim objXmlHttp
Set objXmlHttp = CreateObject("Msxml2.XMLHttp")
Function Main()
dim filesys, filetxt, getname, path, dest_file, file_name, src_url
file_name = "data_20080407.txt"
dest_file = "c:\datafile\" + file_name
src_url = "http://remotesrvr:8080/datafiles/eachday/" + file_name
objXmlHttp.Open "POST", src_url, False
objXmlHttp.onreadystatechange = getref("HandleStateChange")
objXmlHttp.Send
if (len(objXmlHttp.responseText) > 1000) then
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile(dest_file, True)
path = filesys.GetAbsolutePathName(dest_file)
getname = filesys.GetFileName(path)
filetxt.WriteLine(objXmlHttp.responseText)
filetxt.Close
end if
Main = DTSTaskExecResult_Success
End Function
Function HandleStateChange()
If (ObjXmlHttp.readyState = 4) Then
'msgbox "Screenscrapping completed .."
End If
End Function
In the above code "objXmlHttp.responseText" gives memory out of exception when the source file size is huge, as it is holding the entire file content in server memory. Need to find out a way to directly stream the source content to a destination location. Is there any way I could achieve this? highly appreciate anyone's immediate help. many thx in advance.
maruthi
|