|
这个功能无非两个测试点
1)如何从远程下载文件到本地
2)如何验证文件下载的正确性
我帮你写个1的脚本,至于如何验证,你自己可以考虑一下,这个就不难了
Function GetRemoteFiels(RemotePath, LocalPath, FileName)
Dim strBody
Dim FilePath
On Error Resume Next
strBody = GetBody(RemotePath)
if Right(LocalPath, 1) <> "\" then LocalPath = LocalPath & "\"
FilePath = LocalPath & GetFileName(RemotePath, FileName)
if SaveToFile(strBody, FilePath) = true and err.Number = 0 then
GetRemoteFiles = true
else
GetRemoteFiles = false
end if
End Function
Function GetBody(url)
Dim Retrieval
Set Retrieval = createObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
Function GetFileName(RemotePath, FileName)
Dim arrTmp
Dim strFileExt
arrTmp = Split(RemotePath, ".")
strFileExt = arrTmp(UBound(arrTmp))
GetFileName = FileName & "." & strFileExt
End Function
Function SaveToFile(Stream, FilePath)
Dim objStream
On Error Resume Next
Set objStream = createObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objstream.write Stream
objstream.SaveToFile FilePath, 2
objstream.Close()
Set objstream = Nothing
if err.Number <> 0 then
SaveToFile = false
else
SaveToFile = true
end if
End Function |
|