재우니의 블로그

 

classic asp 로 사이트 주소 url 경로를 통해 파일다운로드 하기

https://stackoverflow.com/a/12274877

 

Download Files from URL using Classic ASP

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 Folder using Classic ASP I tried to use...

stackoverflow.com

사용법은 SaveFileFromUrl "https://xxx.com/data/site.pdf","D:\FileData\site.pdf" 이런식으로 사용하면 된다.

public function SaveFileFromUrl(Url, FileName)
    dim objXMLHTTP, objADOStream, objFSO

    Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")

    objXMLHTTP.open "GET", Url, 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(FileName) Then objFSO.DeleteFile FileName
        Set objFSO = Nothing

        objADOStream.SaveToFile FileName
        objADOStream.Close
        Set objADOStream = Nothing

        SaveFileFromUrl = objXMLHTTP.getResponseHeader("Content-Type")
    else
        SaveFileFromUrl = ""
    End if

    Set objXMLHTTP = Nothing
end function