使用经典 ASP 从 URL 下载文件 [英] Download Files from URL using Classic ASP
问题描述
我有几个链接到 pdf 示例的 url
I have few urls which are linked to a pdf example
abc.com/1.pdfabc.com/2g.pdfabc.com/i8.pdf
abc.com/1.pdf abc.com/2g.pdf abc.com/i8.pdf
我想做的是使用 Classic ASP 在文件夹中自动下载 PDF
What i wanted to do is Download the PDFs automatically in a Folder using Classic ASP
我尝试使用此代码 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.
我想自动完成.
推荐答案
我使用了user580950发布的代码和AnthonyWJones的评论,并创建了代码的函数版本.调用该函数,它返回下载文件的内容类型,如果没有找到该文件,则返回一个空字符串.
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 从 URL 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!