'====================================================================
'Process name: SaveRemoteFile
'Function: Save remote files to local
'Parameter: LocalFileName------local file name
'Parameters: RemoteFileUrl-----Remote File URL
'====================================================================
FunctionSaveRemoteFile(LocalFileName,RemoteFileUrl)
SaveRemoteFile=True
dimAds,Retrieval,GetRemoteData
OnErrorResumeNext
SetRetrieval=Server.CreateObject("Microsoft.XMLHTTP")
WithRetrieval
.Open"Get",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
.SaveToFilesserver.MapPath(LocalFileName),2
.Cancel()
.Close()
EndWith
IfErr.number<>0then
SaveRemoteFile=False
ExitFunction
Err.Clear
EndIf
SetAds=nothing
endFunction