如何从服务器下在资料后保存在pc上?(提供原码请高手修改)

msgsnd 2003-12-19 11:03:38
<%
Path=request.querystring("p")
if left(lcase(path),7) <> "http://" then
'Response.Redirect Path
Response.write "local file!"
else
RemoteFile(Path)
end if

Sub RemoteFile(sPath)
FileName = GetFileName(sPath)
'FilePath = Server.MapPath(".") & "\MyData\"&FileName
FilePath = "C:\MyData\"&FileName
trim FilePath
Response.Write FilePath&"<br>"
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
if objFso.FileExists(FilePath) Then
'Response.Redirect "/MyData/" & FileName
Response.write "remote file has been downloaded!"
Else
t = GetBody(Path)
Response.BinaryWrite t
Response.Flush
SaveFile t,FilePath
End if
Set objFso = Nothing
End Sub

Function GetFileName(str)
str = Replace(lcase(str),"http://","")
str = Replace(str,"/","")
str = replace(str,vbcrlf,"")
GetFileName = str
End Function

Function GetBody(url)
'on error resume next
'Response.Write url
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
'GetBody = .ResponseText
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function


Sub SaveFile(strBody,fName)
Set objStream = Server.CreateObject("ADODB.Stream")

lenstr=len(strBody)
dim code()
ReDim code(lenstr)
i = 0
Do Until i = lenstr-1
code(i) = asc("a")
'code(i) = asc(mid(strBody,i,1))
i = i + 1
Loop

With objStream
.Type = 2'adTypeBinary
.Open
'.Charset = "UNICODE"
.Position = 0
'.WriteText = strBody'mid(strBody,0)
.Write = code
Response.write "Len:"&.size
.SaveToFile fName,2
.Close
End With
Set objStream = Nothing
End Sub

%>
...全文
53 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
swich 2003-12-19
  • 打赏
  • 举报
回复
顶起来
Tal 2003-12-19
  • 打赏
  • 举报
回复
帮你顶
msgsnd 2003-12-19
  • 打赏
  • 举报
回复
现在我的问题是:下载后总是比原来的多两个字节。
online 2003-12-19
  • 打赏
  • 举报
回复
你可以把下载后的文件与源文件用二进制编辑器打开分析

可能是文件头附加了额外的信息

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧