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

blossomparkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Piotr StrycharzSoftware/web developerCommented:
I did check your code and it works. The reason must be in the infrastructure (permissions?). I believe that you do not need SEE_MASK_NOZONECHECKS variable as you do not run any program (you are just saving binary). Also - the compiler complains about the syntax :
bStrm.Open()

Open in new window

I had to change to (may depend on compiler):
bStrm.Open

Open in new window

Check if saving to local disk helps (set SaveLoc_CrArr  to 'C:\Location\file...'). Here goes code that works:


Function Test()

uName = "domain\user"
pwd = "password"

URL_CrArr = "https://www.test.com/Logo.png"

SaveLoc_CrArr = "\\server\location\Logo.png"

'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

'get first file
xHttp.Open "GET", URL_CrArr, False, uName, pwd
xHttp.Send
bStrm.Type = 1 '//binary
bStrm.Open
bStrm.write (xHttp.responseBody)
If Err = 0 Then bStrm.savetofile SaveLoc_CrArr, 2 '//overwrite
bStrm.Close

End Function

Open in new window


What does this question have to do with Powershell? BTW with Powershell this would be MUCH simpler (without checks of course):

$wc = New-Object System.Net.WebClient
$wc.Credentials = New-Object System.Net.NetworkCredential "UserName", "Password", "DOMAIN"
[System.IO.File]::WriteAllBytes('C:\TEMP\Logo.png', $wc.DownloadData('https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'))
$wc.Dispose()

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
blossomparkAuthor Commented:
Hi Piotr,
thanks for your input....will try and get back to you, thanks
0
blossomparkAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.