日期:2014-05-16 浏览次数:20915 次
'过程名:SaveRemoteFile
'作用:保存远程的文件到本地
'参数:LocalFileName ------ 本地文件名
'参数:RemoteFileUrl ------ 远程文件URL
'参数:Referer ------ 远程调用文件(对付防采集的,用内容页地址,没有防的留空)
'==================================================
Public Function SaveRemoteFile1(LocalFileName, RemoteFileUrl, Referer)
SaveRemoteFile = True
Dim Ads, Retrieval, GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False
If Referer <> "" Then .setRequestHeader "Referer", Referer
On Error Resume Next
If Err <> 0 Then
Err.Clear
SaveRemoteFile1 = False
Exit Function
End If
.Send
If .Readystate <> 4 Then
SaveRemoteFile1 = False
Exit Function
End If
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set stm = server.CreateObject("Adodb.Stream")
stm.Type = 1 '以本模式读取
stm.mode = 3
stm.Open
stm.Write GetRemoteData
stm.SaveToFile server.MapPath(LocalFileName), 2
stm.flush
stm.Close
Set stm = Nothing
End Function
url = "http://192.168.1.1/test/list.asp"
nfilename = "list.htm"
SaveRemoteFile1(nfilename,url,"")
Response.Write "<center>生成静态list.htm成功!</center>"