欢迎光临
我们一直在努力

使用XMLHttp和ADODB.Stream取得远程文件并保存到本地

建站超值云服务器,限时71元/月

<%

****************************************************************************

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

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用XMLHttp和ADODB.Stream取得远程文件并保存到本地
分享到: 更多 (0)

相关推荐

  • 暂无文章