今天寫程式時突然想到做一個檔案的備份,把網站上的Database Backup到本地機上。一個簡單的小程式,做成可執行檔檔案,用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