?
Solved

Download File with ServerXMLHTTP with setProxyCredentials

Posted on 2011-03-15
3
Medium Priority
?
2,703 Views
Last Modified: 2012-05-11
I am trying to run a VBScrpit to download a file daily from a website. In order to do this I need to set the proxy credentials. THe scrpit below works inside the network, and I have verified that the two URLs are accurate (if put in IE both go where I want) but after I enter my proxy credentials and do a .send the object status returns HTTP Error 407 (proxy authorization required) I know that the credentials I have are what I enter manually, although I reliase that it may not be the full username. Also I cant bypass the proxy because the website verifies the IP address before allowing me to login.  Any suggestions?  
Dim sFileURL, objXMLHTTP, objADOStream, objFSO, sLocation,  username, password,url
     
 username = "my username"
 password = "my password"
 sFileURL = "Login URL"
 sLocation = "Path" 
 url = "File URL"
 
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")

 objXMLHTTP.setProxy 2, "my proxy"   
 objXMLHTTP.Open "GET", sFileURL, False 
 objXMLHTTP.setProxyCredentials username, password
 objXMLHTTP.send()
 
If objXMLHTTP.Status <> 200 Then    
	msgbox objXMLHTTP.status 
End if 
 
objXMLHTTP.Open "GET", url, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
 
        Set objADOStream = CreateObject("ADODB.Stream")
        objADOStream.Open
 
        objADOStream.Type = 1
        objADOStream.Write objXMLHTTP.ResponseBody
 
        objADOStream.Position = 0
 
        Set objFSO = CreateObject
                     ("Scripting.FileSystemObject")
 
         If objFSO.FileExists(sLocation) Then 
                      objFSO.DeleteFile sLocation
 
        
         Set objFSO = Nothing
 
        
         objADOStream.SaveToFile sLocation
 
         objADOStream.Close
  
         Set objADOStream = Nothing
 
End If
 
Set objXMLHTTP = Nothing

Open in new window

0
Comment
Question by:JClayton7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:JClayton7
ID: 35139730
I got it to work, It was a username issue. But the file i am trying to download is a .gz and all I seem to be getting is the XML not the actual file. Any help would be greatly appreciated!
0
 
LVL 6

Accepted Solution

by:
judgeking earned 1000 total points
ID: 35140297
This uses different code objects, but it works for most downloads.  Don't forget, in the server IIS settings, it must be set to serve the type of file you're trying to download, or else you'll receive an error.


Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Sub Form_Load()
    Dim ret As Long
    Dim buff As String
    
    Call DeleteUrlCacheEntry("http://craphound.com/msftdrm.txt")
    ret = URLDownloadToFile(0, "http://craphound.com/msftdrm.txt", "c:\test.txt", 0, 0)
    If ret = 0 Then
        Open "c:\test.txt" For Binary As 1
            buff = Space$(LOF(1))
            Get #1, 1, buff
        Close 1
    End If
End Sub

Open in new window

0
 
LVL 6

Expert Comment

by:judgeking
ID: 35402817
Clayton, any update?
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question