国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

支持斷點下載的VBS代碼

2019-10-26 18:05:33
字體:
來源:轉載
供稿:網友
之前我就介紹過VBScript語言的強大。今天再給出一個支持斷點下載的VBS代碼。
并附上VBS代碼的解析,不懂的朋友可以配合微軟的SCRIPT56.CHM文檔自學。很簡單,
VBS的好處就是代碼易于理解。基本上每行代碼執行功能都用英文表示出來了。
這個代碼也是對我以前介紹的VBS下載功能的補充。
老規矩,復制保存為dl.vbe。
不過這個VBS的代碼的不同之處不是雙擊運行,而是在CMD命令行下執行。

下載功能執行的格式是: cscript.exe dl.vbs (目標文件地址)

[以下載MetaSploit的WIn32版本為例。在CMD中輸入:cscript.exe dl.vbs http://spool.metasploit.com/releases/framework-3.2.exe]

36.7M的文件下載用了7分多鐘,而迅雷用了1分50秒。

代碼如下:
復制代碼 代碼如下:

if (lcase(right(wscript.fullname,11))="wscript.exe") then'判斷腳本宿主的名稱'
die("Script host must be CScript.exe.") '腳本宿主不是CScript,于是就die了'
end if

if wscript.arguments.count<1 then'至少要有一個參數'
die("Usage: cscript webdl.vbs url [filename]") '麻雀雖小五臟俱全,Usage不能忘'
end if

url=wscript.arguments(0) '參數數組下標從0開始'
if url="" then die("URL can't be null.") '敢唬我,空url可不行'
if wscript.arguments.count>1 then'先判斷參數個數是否大于1'
filename=wscript.arguments(1) '再訪問第二個參數'
else '如果沒有給出文件名,就從url中獲得'
t=instrrev(url,"/") '獲得最后一個"/"的位置'
if t=0 or t=len(url) then die("Can not get filename to save.") '沒有"/"或以"/"結尾'
filename=right(url,len(url)-t)'獲得要保存的文件名'
end if
if not left(url,7)="http://" then url="http://"&url'如果粗心把“http://”忘了,加上'

set fso=wscript.createobject("Scripting.FileSystemObject") 'FSO,ASO,HTTP三個對象一個都不能少'
set aso=wscript.createobject("ADODB.Stream")
set http=wscript.createobject("Microsoft.XMLHTTP")

if fso.fileexists(filename) then '判斷要下載的文件是否已經存在'
start=fso.getfile(filename).size '存在,以當前文件大小作為開始位置'
else
start=0 '不存在,一切從零開始'
fso.createtextfile(filename).close '新建文件'
end if

wscript.stdout.write "Connectting..." '好戲剛剛開始'
current=start '當前位置即開始位置'
do
http.open "GET",url,true'這里用異步方式調用HTTP'
http.setrequestheader "Range","bytes="&start&"-"&cstr(start+20480) '斷點續傳的奧秘就在這里'
http.setrequestheader "Content-Type:","application/octet-stream"
http.send '構造完數據包就開始發送'

for i=1 to 120 '循環等待'
if http.readystate=3 then showplan() '狀態3表示開始接收數據,顯示進度'
if http.readystate=4 then exit for '狀態4表示數據接受完成'
wscript.sleep 500 '等待500ms'
next
if not http.readystate=4 then die("Timeout.") '1分鐘還沒下完20k?超時!'
if http.status>299 then die("Error: "&http.status&" "&http.statustext) '不是吧,又出錯?'
if not http.status=206 then die("Server Not Support Partial Content.") '服務器不支持斷點續傳'
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天峻县| 涞水县| 南汇区| 奉节县| 潼南县| 辽宁省| 育儿| 山阳县| 蒙城县| 兴隆县| 和顺县| 新津县| 新安县| 湟中县| 石首市| 金昌市| 乃东县| 桂阳县| 辰溪县| 海淀区| 松桃| 嘉义市| 云阳县| 五莲县| 杨浦区| 京山县| 鹿邑县| 塔河县| 全椒县| 曲松县| 什邡市| 泗洪县| 新龙县| 政和县| 巩留县| 双柏县| 探索| 丹东市| 泾阳县| 澜沧| 安徽省|