'================================================ ==============
'Process name: SaveRemoteFile
'Usage: Save the remote file to the local device.
'Parameter: LocalFileName ------ local file name
'Parameter: RemoteFileUrl ------ Remote File 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
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
If Err. number <> 0 then
SaveRemoteFile = False
Exit Function
Err. Clear
End If
Set Ads = nothing
End Function