<%
****************************************************************************
pagename:getremotefiles.asp
function:download the files to server
author:xiaotian
last modified at:2003-3-19
****************************************************************************
取得远程文件并保存到本地
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
建立xmlhttp对象
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
建立adodb.stream对象,必须要ado 2.5以上版本
set objstream = server.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
%>
