In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use vbs to support breakpoint downloads, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
And attach the parsing of VBS code, friends who do not understand can cooperate with Microsoft SCRIPT56.CHM documents to self-study. It's simple,
The advantage of VBS is that the code is easy to understand. Basically every line of code execution function is expressed in English.
This code also complements the VBS download function that I introduced earlier.
The old rule is to copy and save as dl.vbe.
However, the difference in this VBS code is not double-click to run, but to execute under the CMD command line.
The format of the download function is: cscript.exe dl.vbs (destination file address)
[the following WIn32 version of MetaSploit is taken as an example. Enter: cscript.exe dl.vbs http://spool.metasploit.com/releases/framework-3.2.exe] in CMD
The file download of 36.7m took more than 7 minutes, while Thunderbolt took 1 minute and 50 seconds.
The code is as follows:
If (lcase (right (wscript.fullname,11)) = "wscript.exe") then' determines the name of the script host'
Die ("Script host must be CScript.exe.") "the script host is not CScript, so it is die"
End if
If wscript.arguments.count1 then' first determines whether the number of parameters is greater than 1'.
Filename=wscript.arguments (1) 'access the second parameter'
Else'if you don't give a file name, get it from url'
T=instrrev (url, "/") 'get the last' / 'position'
If twee0 or t=len (url) then die ("Can not get filename to save.") "there is no" / "or ends with" / "
Filename=right (url,len (url)-t) 'get the file name to save'
End if
If not left (url,7) = "http://" then url=" http://"&url' if you forget "http://"" carelessly, add'
Set fso=wscript.createobject ("Scripting.FileSystemObject") 'none of the three objects of FSO,ASO,HTTP can be missing'
Set aso=wscript.createobject ("ADODB.Stream")
Set http=wscript.createobject ("Microsoft.XMLHTTP")
If fso.fileexists (filename) then 'determine whether the file to be downloaded already exists'
Start=fso.getfile (filename) .size 'exists, starting with the current file size'
Else
Start=0 'does not exist, everything starts from scratch'
Fso.createtextfile (filename). Close 'New File'
End if
Wscript.stdout.write "Connectting..." "the fun has just begun."
Current=start 'current position is the start position'
Do
Http.open "GET", url,true' here calls HTTP' asynchronously
Http.setrequestheader "Range", "bytes=" & start& "-" & cstr (start+20480) 'here is the secret of breakpoint continuation'
Http.setrequestheader "Content-Type:", "application/octet-stream"
Http.send 'start to send the packet after constructing it'
For iTunes 1 to 120 'Loop wait'
If http.readystate=3 then showplan () 'status 3 means to start receiving data and show progress'
If http.readystate=4 then exit for 'status 4 indicates that data acceptance is complete'
Wscript.sleep 500 'wait 500ms'
Next
If not http.readystate=4 then die ("Timeout.")'20 k in 1 minute? timeout!'
If http.status > 299 then die ("Error:" & http.status& "& http.statustext)'Oh no, another mistake?'
If not http.status=206 then die ("Server Not Support Partial Content.") "the server does not support resuming upload from breakpoints"
Aso.type=1 'data stream type set to byte'
Aso.open
Aso.loadfromfile filename 'Open File'
Aso.position=start' sets the initial position of the file pointer'
Aso.write http.responsebody 'write data'
Aso.savetofile filename,2 'overwrite Save'
Aso.close
Range=http.getresponseheader ("Content-Range") 'get the "Content-Range" in the http header
If range= "" then die ("Can not get range.")' Without it, I don't know if I've finished downloading it.
Temp=mid (range,instr (range, "-") + 1) 'Content-Range is similar to 123-456 Universe 789'
Current=clng (left (temp,instr (temp, "/")-1)) '123 is the start position, 456 is the end position'
Total=clng (mid (temp,instr (temp, "/") + 1)) '789 is the total number of bytes in the file'
If total-current=1 then exit do 'the end position is less than the total size by 1 indicates that the transfer is complete'
Start=start+20480'or download another 20k'
Loop while true
Wscript.echo chr (13) & "Download (" & total& ") Done." "after downloading, display the total number of bytes"
The function die (msg) 'function name comes from the Perl built-in function die'.
Wscript.echo msg 'confess the last words ^ _ ^'
Wscript.quit 'went to see Marx'
End function
Function showplan () 'Show download progress'
If i mod 3 = 0 then c = "/" 'simple dynamic effect'
If i mod 3 = 1 then c = "-"
If i mod 3 = 2 then c = "\"
Wscript.stdout.write chr (13) & "Download (" & current& ")" & c&chr (8)'13 ASCII code is back to the beginning of the line, and No. 8 is backspace'
End function
Thank you for reading this article carefully. I hope the article "how to use vbs to support breakpoint downloads" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.