Link to home
Start Free TrialLog in
Avatar of blossompark
blossomparkFlag for Ireland

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
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")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Piotr Strycharz
Piotr Strycharz
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blossompark

ASKER

Hi Piotr,
thanks for your input....will try and get back to you, thanks
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