• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2896
  • Last Modified:

Download File with ServerXMLHTTP with setProxyCredentials

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
JClayton7
Asked:
JClayton7
  • 2
1 Solution
 
JClayton7Author Commented:
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
 
judgekingCommented:
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
 
judgekingCommented:
Clayton, any update?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now