blossompark
asked on
vb script unable to download file from internet
Hi,
I am using the following VB script to download files from the internet.
however I am getting a "Write to file failed" message .
full message
I have inserted some troubleshooting code (see 'troubleshoot code section), which tries to download the responseBody output but that fails.
The Status value=200 which I believe means the file exists, so I'm thinking the issue is around downloading the file to the directory.
Any guidance appreciated
I am using the following VB script to download files from the internet.
however I am getting a "Write to file failed" message .
full message
ADODB.Stream: Write to file failed.I have write permissions on the folder I am trying to save to, I can create a file in that folder manually.
I have inserted some troubleshooting code (see 'troubleshoot code section), which tries to download the responseBody output but that fails.
The Status value=200 which I believe means the file exists, so I'm thinking the issue is around downloading the file to the directory.
Any guidance appreciated
'on error resume next
'set up the environment
set oShell= CreateObject("Wscript.Shell")
set oEnv = oShell.Environment("PROCESS")
'below prevents the @OPen File - Security Warning box from opening
'because the file is downloading from the internet it
'is considered dangerous
oEnv("SEE_MASK_NOZONECHECKS") = 1
uName = "testdomain\rob"
pwd= "password"
URL_CrArr =
"http://testframework.test.com:19390/testApplicationFramework/GSUMISWeb/TESTExcelReport.go?
SP=p_ReportQueryGet&P=LONDON&P=UK&P=Monthly&P=p_MIS_ca_details_master_Get&SrchDataSet=p_Report
QueryGet4"
URL_Loans
="http://testframework.test.com:19390/testApplicationFramework/GSUMISWeb/TESTExcelReport.go?
SP=p_ReportQueryGet&P=LONDON&P=UK&P=Monthly&P=p_MIS_loan_detail_master_Get&SrchDataSet=p_Repor
tQueryGet4"
'to-do: add in the additional reports for month end
SaveLoc_CrArr="\\CLIENT.TEST.COM\UKB\Imports\Arrangements.xls"
SaveLoc_Loans="\\CLIENT.TEST.COM\UKB\Imports\LoanDetails.xls"
'to-do: add in the additional reports for month end
'set up the download jobs
dim xHttp: Set xHttp = createobject("MSXML2.ServerXMLHTTP.6.0")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.setTimeouts 5000,5000,5000,5000
'Troubleshoot code
xHttp.Open "GET", URL_CrArr, False, uName ,pwd
xHttp.Send
bStrm.type = 1 '//binary
bStrm.Open()
bStrm.write (xHttp.responseBody)
msgbox (xHttp.Status) 'if 200 then file found
msgbox (xHttp.responseBody)
If XHttp.Status = 200 Then
With CreateObject("ADODB.Stream")
.Type = 1 'adTypeBinary
.Open
.Write XHTTP.responseBody
.SaveToFile SaveLoc_CrArr
.Close
End With
END IF
bStrm.close
'get first file
xHttp.Open "GET", URL_CrArr, False, uName ,pwd
xHttp.Send
bStrm.type = 1 '//binary
bStrm.Open()
bStrm.write (xHttp.responseBody)
msgbox (xHttp.Status)
if err=0 then bStrm.savetofile SaveLoc_CrArr, 2 '//overwrite
bStrm.close
'get the second file
xHttp.Open "GET", URL_Loans, False, uName, pwd
xHttp.Send
bStrm.type = 1 '//binary
bStrm.Open()
bStrm.write (xHttp.responseBody)
if err=0 then bStrm.savetofile SaveLoc_Loans, 2 '//overwrite
bStrm.close
'finall, clean up
oEnv.Remove("SEE_MASK_NOZONECHECKS")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Piotr,
thank you for your input, I will use this as a basic for resolving this issue, have not tried it yet but will do when i get the opportunity later this week.
Regarding Powershell, that is due to my ignorance of what powershell is, i put it in as I assumed all these command shells are one and the same thing
thank you for your input, I will use this as a basic for resolving this issue, have not tried it yet but will do when i get the opportunity later this week.
Regarding Powershell, that is due to my ignorance of what powershell is, i put it in as I assumed all these command shells are one and the same thing
ASKER
thanks for your input....will try and get back to you, thanks