使用传统的ASP从网址下载文件 [英] Download Files from URL using Classic ASP

查看:223
本文介绍了使用传统的ASP从网址下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接到PDF的例子几个URL

I have few urls which are linked to a pdf example

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

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

我想要做的是使用一个文件夹自动下载PDF文件经典ASP

What i wanted to do is Download the PDFs automatically in a Folder using Classic ASP

我试图用这个code <一个href=\"http://blog.netnerds.net/2007/01/classic-asp-push-file-downloads-from-directory-outside-of-the-web-root/\" rel=\"nofollow\">http://blog.netnerds.net/2007/01/classic-asp-push-file-downloads-from-directory-outside-of-the-web-root/
但是对于HTTP这并不工作,如果这些文件是本地它的作品不错。

I tried to use this code http://blog.netnerds.net/2007/01/classic-asp-push-file-downloads-from-directory-outside-of-the-web-root/ but this doesnt work for Http it works good if the files are local.

我要自动完成。

推荐答案

我用code发表user580950和AnthonyWJones注释,并创建了code的功能版本。调用函数,如果未找到该文件返回下载的文件或空字符串的内容类型。

I used the code posted by user580950 and the comment by AnthonyWJones and created a function version of the code. Call the function and it returns the content type of the file downloaded or an empty string if the file wasn't found.

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

这篇关于使用传统的ASP从网址下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆