当前位置:编程学习 > asp >>

SaveRemoteFile函数之asp实现保存远程的文件到本地的代码

答案:'==================================================
'过程名:SaveRemoteFile
'作 用:保存远程的文件到本地
'参 数:LocalFileName ------ 本地文件名
'参 数:RemoteFileUrl ------ 远程文件URL
'==================================================
Function SaveRemoteFile(LocalFileName,RemoteFileUrl)
SaveRemoteFile=True
dim Ads,Retrieval,GetRemoteData
On Error Resume Next
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
If .Readystate<>4 or .Status > 300 then
SaveRemoteFile=False
Exit Function
End If
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
'If LenB(GetRemoteData) < 100 Then Exit Function
'If MaxFileSize > 0 Then
'If LenB(GetRemoteData) > 5000 Then Exit Function
Response.Write(Round(LenB(GetRemoteData)/1024)) & "KB"
'End If
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
If Err.number<>0 then
SaveRemoteFile=False
Exit Function
Err.Clear
End If
Set Ads=nothing
end Function

上一个:FpHtmlEnCode 函数之标题过滤特殊符号的代码
下一个:CheckFile函数之asp实现检查某一文件是否存在的代码

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,