今天寫程序時突然想到做一個文件的備份,把網站上的數據庫備份到本地機上。一個簡單的小程序,做成可執行的文件,用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