Download Files from URL using Classic ASP

前端 未结 2 715
醉梦人生
醉梦人生 2021-01-05 16:30

I have few urls which are linked to a pdf example

abc.com/1.pdf abc.com/2g.pdf abc.com/i8.pdf

What i wanted to do is Download the PDFs automatically in a Fo

2条回答
  •  悲&欢浪女
    2021-01-05 17:03

    I got this code somewhere on the internet if anyone wants to use it.

    <%
    Server.ScriptTimeout = 60 * 20
    ' Set your settings
    strFileURL = "http://pathtofile.zip"
    strHDLocation = "c:\filename.zip"
    
    ' Fetch the file
    Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
    
    objXMLHTTP.Open "GET", strFileURL, False
    objXMLHTTP.Send()
    
    If objXMLHTTP.Status = 200 Then
        Set objADOStream = CreateObject("ADODB.Stream")
        objADOStream.Open
        objADOStream.Type = 1 'adTypeBinary
    
        objADOStream.Write objXMLHTTP.ResponseBody
        objADOStream.Position = 0 'Set the stream position to the start
    
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        If objFSO.FileExists(strHDLocation) Then objFSO.DeleteFile strHDLocation
        Set objFSO = Nothing
    
        objADOStream.SaveToFile strHDLocation
        objADOStream.Close
        Set objADOStream = Nothing
    End if
    
    Set objXMLHTTP = Nothing
    %> 
    

提交回复
热议问题