- ·上一篇文章:注册表-批处理-VBS之间的相互结合应用
- ·下一篇文章:(VBS+cmd)国家授时中心时间同步器
- ·百度中搜索更多的关于“用VBS可执行程序+Xmlhttp下载备份网上文件的代码”相关内容
- ·谷歌中搜索更多的关于“用VBS可执行程序+Xmlhttp下载备份网上文件的代码”相关内容
- ******申明******
- 本站文章内容有部分为收录网络中其他网友内容,DOS资源站不保证所有的代码都适合你使用。
- 由于编辑匆忙,有可能造成某些脚本文件出现丢失代码或代码无法运行的情况,请网友根据情况自行修改。
- 如果能将出错部分反馈给我,那就更好了。
用VBS可执行程序+Xmlhttp下载备份网上文件的代码
今天写程序时突然想到做一个文件的备份,把网站上的数据库备份到本地机上。一个简单的小程序,做成可执行的文件,用VBS最简单方便了。 'On Error Resume Next
Dim iRemote,iLocal
iRemote = InputBox("请输入远程文件路径:")
Set xPost = CreateObject("Microsoft.XMLHTTP")
xPost.Open "GET",iRemote,0
xPost.Send()
Set stream = CreateObject("ADODB.Stream")
stream.Mode = 3
stream.Type = 1
stream.Open()
stream.Write(xPost.responseBody)
if (stream.size<10240) then
MsgBox("远程文件不存在!")
else
SaveFile
end if
stream.close
set stream = nothing
' 保存文件
function SaveFile
iLocal = InputBox("请输入本机保存路径:")
Set fso = CreateObject("Scripting.FileSystemObject")
returnValue = "0"
if (fso.FileExists(iLocal)) then
returnValue = MsgBox("'"&iLocal&"'文件已存在,真的要覆盖吗?",vbYesNoCancel,"确认框")
end if
set fso = nothing
if (returnValue = "6" or returnValue = "0") then '覆盖
stream.SaveToFile iLocal,2
MsgBox("文件备份成功!")
elseif (returnValue = "7") then
SaveFile
end if
end function
Dim iRemote,iLocal
iRemote = InputBox("请输入远程文件路径:")
Set xPost = CreateObject("Microsoft.XMLHTTP")
xPost.Open "GET",iRemote,0
xPost.Send()
Set stream = CreateObject("ADODB.Stream")
stream.Mode = 3
stream.Type = 1
stream.Open()
stream.Write(xPost.responseBody)
if (stream.size<10240) then
MsgBox("远程文件不存在!")
else
SaveFile
end if
stream.close
set stream = nothing
' 保存文件
function SaveFile
iLocal = InputBox("请输入本机保存路径:")
Set fso = CreateObject("Scripting.FileSystemObject")
returnValue = "0"
if (fso.FileExists(iLocal)) then
returnValue = MsgBox("'"&iLocal&"'文件已存在,真的要覆盖吗?",vbYesNoCancel,"确认框")
end if
set fso = nothing
if (returnValue = "6" or returnValue = "0") then '覆盖
stream.SaveToFile iLocal,2
MsgBox("文件备份成功!")
elseif (returnValue = "7") then
SaveFile
end if
end function

