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

2018-09-06 12:16

阅读:461

  ==================================================
过程名:SaveRemoteFile
作用:保存远程的文件到本地
参数:LocalFileName------本地文件名
参数:RemoteFileUrl------远程文件URL
==================================================
FunctionSaveRemoteFile(LocalFileName,RemoteFileUrl)
SaveRemoteFile=True
dimAds,Retrieval,GetRemoteData
OnErrorResumeNext
SetRetrieval=Server.CreateObject(Microsoft.XMLHTTP)
WithRetrieval
.OpenGet,RemoteFileUrl,False,,
.Send
If.Readystate<>4or.Status>300then
SaveRemoteFile=False
ExitFunction
EndIf
GetRemoteData=.ResponseBody
EndWith
SetRetrieval=Nothing
IfLenB(GetRemoteData)<100ThenExitFunction
IfMaxFileSize>0Then
IfLenB(GetRemoteData)>5000ThenExitFunction
Response.Write(Round(LenB(GetRemoteData)/1024))&KB
EndIf
SetAds=Server.CreateObject(Adodb.Stream)
WithAds
.Type=1
.Open
.WriteGetRemoteData
.SaveToFileserver.MapPath(LocalFileName),2
.Cancel()
.Close()
EndWith
IfErr.number<>0then
SaveRemoteFile=False
ExitFunction
Err.Clear
EndIf
SetAds=nothing

endFunction


评论


亲,登录后才可以留言!