首页 安全基础 网络安全 安全协议 病毒分析 防火墙 OS安全 无线安全 Web安全 PKI与PMI 入侵检测 经典案例
安全审计 设备安全 安全管理 安全标准 法律法规 隔离网闸 DB安全 XML安全 开源项目 资源下载 安全论坛 备份恢复
 当前位置:首页>>xml安全>>xml基础>>正文
远程获取内容,并将内容存在本地电脑上,包括任何文件
文章出处:开发者俱乐部 作者:嘻哈呵嘿    发布时间:2004-12-27   点击:0
 

    <%
  '------------------------------------------------------------------------
  '-------------------无垠网域:http://www.5inet.net/ ---------------------
  '-------------------作者:嘻哈呵嘿 ,webmaster@5inet.net -----------------
  '----------远程获取内容,并将内容存在本地电脑上,包括任何文件!----------
  '---------------利用xmlhttp和adodb.stream,酷!绝对原创!-----------------
  'on error resume next
  'set the content type to the specific type that you are sending.
  'response.contenttype = "image/jpeg"
  '-------------------------------定义输出格式----------------------------- 

  path=request.querystring("p")
  spath = path
  if left(lcase(path),7) <> "http://" then 
  '-------------如果前面没有http就是本地文件,交给localfile处理------------
  localfile(path)
  else
  '--------------------否则为远程文件,交给remotefile处理------------------
  remotefile(path)
  end if
  'response.write err.description 

  sub localfile(path)
  '-------------------如果为本地文件则简单的跳转到该页面-------------------
  response.redirect path
  end sub

  sub remotefile(spath)
  '-------------------------处理远程文件函数------------------------------
  filename = getfilename(spath)
  '-------------getfilename为把地址转换为合格的文件名过程-------------
  filename = server.mappath("/uploadfile/cache/" & filename)
  set objfso = server.createobject("scripting.filesystemobject")
  'response.write filename
  if objfso.fileexists(filename) then
  '--------------检查文件是否是已经访问过,如是,则简单跳转------------
  response.redirect "/uploadfile/cache/" & getfilename(path)
  else
  '----------------否则的话就先用getbody函数读取----------------------
  'response.write path
  t = getbody(path)
  '-----------------用二进制方法写到浏览器上--------------------------
  response.binarywrite t
  response.flush
  '-----------------输出缓冲------------------------------------------
  savefile t,getfilename(path)
  '------------------将文件内容缓存到本地路径,以待下次访问-----------
  end if 
  set objfso = nothing
  end sub

  function getbody(url) 
  '-----------------------本函数为远程获取内容的函数---------------------
  'on error resume next
  'response.write url
  set retrieval = createobject("microsoft.xmlhttp") 
  '----------------------建立xmlhttp对象-----------------------------
  with retrieval 
  .open "get", url, false, "", "" 
  '------------------用get,异步的方法发送-----------------------
  .send 
  'getbody = .responsetext
  getbody = .responsebody
  '------------------函数返回获取的内容--------------------------
  end with 
  set retrieval = nothing 
  'response.write err.description 
  end function

  function getfilename(str)
  '-------------------------本函数为合格化的文件名函数-------------------
  str = replace(lcase(str),"http://","")
  str = replace(lcase(str),"//","/")
  str = replace(str,"/","")
  str = replace(str,vbcrlf,"")
  getfilename = str
  end function

  sub savefile(str,fname)
  '-------------------------本函数为将流内容存盘的函数-------------------
  'on error resume next
  set objstream = server.createobject("adodb.stream")
  '--------------建立adodb.stream对象,必须要ado 2.5以上版本---------
  objstream.type = adtypebinary
  '-------------以二进制模式打开-------------------------------------
  objstream.open
  objstream.write str
  '--------------------将字符串内容写入缓冲--------------------------
  'response.write fname
  objstream.savetofile "c:\inetpub\myweb\uploadfile\cache\" & fname,adsavecreateoverwrite
  '--------------------将缓冲的内容写入文件--------------------------
  'response.binarywrite objstream.read 
  objstream.close()
  set objstream = nothing
  '-----------------------关闭对象,释放资源-------------------------
  'response.write err.description 
  end sub
  %> 



作者:
[返回顶部↑]  [推荐好友] [查看评论]  
用户名: 新注册) 密码: 匿名评论 [查看评论]  发表评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 
↑文章搜索
  关键字:  
  范  围:  
  开始搜索  
※相关文章※
 

◎用xalan在ie中浏览xml文件
◎用digester简化xml文档处理
◎用jdom处理xml文档
◎用digester简化xml文档处理
◎用dhtml来模拟实现下拉菜单
◎用digester简化xml配置文件
◎用c#与xml创建动态分层菜

 
※热点文章※
  ·[.net]:在managed c++中处
·[.net] 在传统com程序中使
·[.net] 在传统com程序中使
·thinking xml用musicbrain
·asp.net+xml开发网络硬盘(
·[.net]:在managed c++中处
·c#来创建和读取xml文档
 

关于我们 | 征搞启示 | 版权信息 | 联系我们 | 友情链接

版权所有:中国信息安全组织 © 2003-2005 Power by DedeCms