今天寫程序時(shí)突然想到做一個(gè)文件的備份,把網(wǎng)站上的數(shù)據(jù)庫備份到本地機(jī)上。一個(gè)簡單的小程序,做成可執(zhí)行的文件,用VBS最簡單方便了。 'On Error Resume Next Dim iRemote,iLocal iRemote = InputBox("請(qǐng)輸入遠(yuǎn)程文件路徑:") 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("遠(yuǎn)程文件不存在!") else SaveFile end if stream.close set stream = nothing
' 保存文件 function SaveFile iLocal = InputBox("請(qǐng)輸入本機(jī)保存路徑:") Set fso = CreateObject("Scripting.FileSystemObject") returnValue = "0" if (fso.FileExists(iLocal)) then returnValue = MsgBox("'"&iLocal&"'文件已存在,真的要覆蓋嗎?",vbYesNoCancel,"確認(rèn)框") 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