开发学院WEB开发ASP ASP保存远程文件到本地(实用版) 阅读

ASP保存远程文件到本地(实用版)

 2009-01-20 10:39:33 来源:WEB开发网   
核心提示:<%Function SaveRemoteFile(LocalFileName,RemoteFileUrl) SaveRemoteFile=Truedim Ads,Retrieval,GetRemoteDataSet Retrieval = Server.CreateObject("Microsoft

<%
Function SaveRemoteFile(LocalFileName,RemoteFileUrl)
   SaveRemoteFile=True
dim Ads,Retrieval,GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.xmlHTTP")
With Retrieval
  .Open "Get", RemoteFileUrl, False, "", ""
  .Send
     If .Readystate<>4 then
       SaveRemoteFile=False
       Exit Function
     End If
  GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
  .Type = 1
  .Open
  .Write GetRemoteData
  .SaveToFile server.MapPath(LocalFileName),2
  .Cancel()
  .Close()
End With
Set Ads=nothing
End Function
%>

<%
'以下为调用示例:
remoteurl="http://www.uyux.cn/logo.gif"'远程文件名(绝对全路径)
localfile=Replace(Replace(Replace(Now(),"-","")," ",""),":","")&Right(remoteurl,4)'本机文件名(可自定义)
If SaveRemoteFile(localfile,remoteurl)=True Then
Response.Write("成功保存:"&localfile)
End If
%>

Tags:ASP 保存 远程

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接