您现在的位置是:网站首页> 编程资料编程资料
SaveRemoteFile函数之asp实现保存远程的文件到本地的代码_应用技巧_
2023-05-25
309人已围观
简介 SaveRemoteFile函数之asp实现保存远程的文件到本地的代码_应用技巧_
'==================================================
'过程名:SaveRemoteFile
'作 用:保存远程的文件到本地
'参 数:LocalFileName ------ 本地文件名
'参 数:RemoteFileUrl ------ 远程文件URL
'==================================================
Function SaveRemoteFile(LocalFileName,RemoteFileUrl)
SaveRemoteFile=True
dim Ads,Retrieval,GetRemoteData
On Error Resume Next
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
If .Readystate<>4 or .Status > 300 then
SaveRemoteFile=False
Exit Function
End If
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
'If LenB(GetRemoteData) < 100 Then Exit Function
'If MaxFileSize > 0 Then
'If LenB(GetRemoteData) > 5000 Then Exit Function
Response.Write(Round(LenB(GetRemoteData)/1024)) & "KB"
'End If
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
If Err.number<>0 then
SaveRemoteFile=False
Exit Function
Err.Clear
End If
Set Ads=nothing
end Function
'过程名:SaveRemoteFile
'作 用:保存远程的文件到本地
'参 数:LocalFileName ------ 本地文件名
'参 数:RemoteFileUrl ------ 远程文件URL
'==================================================
Function SaveRemoteFile(LocalFileName,RemoteFileUrl)
SaveRemoteFile=True
dim Ads,Retrieval,GetRemoteData
On Error Resume Next
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
If .Readystate<>4 or .Status > 300 then
SaveRemoteFile=False
Exit Function
End If
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
'If LenB(GetRemoteData) < 100 Then Exit Function
'If MaxFileSize > 0 Then
'If LenB(GetRemoteData) > 5000 Then Exit Function
Response.Write(Round(LenB(GetRemoteData)/1024)) & "KB"
'End If
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
If Err.number<>0 then
SaveRemoteFile=False
Exit Function
Err.Clear
End If
Set Ads=nothing
end Function
相关内容
- ASP检查文件与目录是否存在的函数代码_应用技巧_
- ReplaceTrim 函数之asp实现过滤掉字符中所有的tab和回车和换行的代码_应用技巧_
- FormatRemoteUrl函数之asp实现格式化成当前网站完整的URL-将相对地址转换为绝对地址的代码_应用技巧_
- ASP+XML实例演练编程代码第1/3页_应用技巧_
- asp实现防止从外部提交数据的三种方法第1/3页_应用技巧_
- asp又一个分页的代码例子_应用技巧_
- asp下的一个很简单的验证码程序第1/3页_应用技巧_
- asp实现一个统计当前在线用户的解决方案_应用技巧_
- 一些Asp技巧和实用解决方法_应用技巧_
- asp下最常用的19个基本技巧第1/2页_应用技巧_
