X
mIRCScripts
By using this site, you understand and agree to us using cookies.
Snippets
  • Uploaded By: entropy
  • Added: 3 months ago
  • Updated: 13 days ago
  • mIRC Version: 7.52+
  • Hits: 194
  • Size: 3.76KB
  • Downloads: 5
  • Review By: westor



Get File v1.1

Downloads a file from the internet. Works with just about all formats.

Example:
/getfile -re "C:\mIRC\img.jpg" http://site.here/img.jpg

Downloads internet image img.jpg to the local mIRC directory.

Switches:
"r" switch - Run the download on completion
"e" switch - Echo to the active window socket details
Both switches are optional

    
  1    0  Login to Vote.


Source Code:
  1.  
  2. ; Get File v1.0 - by entropy 2020
  3.  
  4. ;================================================================================== EXAMPLE
  5.  
  6. ; Example: /getfile [-re] <"path\file.ext"> <site link>
  7.  
  8. ; =================================================================================
  9. ; Example: /getfile -re "C:\mIRC\img.jpg" http://site.here/img.jpg
  10. ; =================================================================================
  11.  
  12. ; "r" switch - Run the download on completion
  13. ; "e" switch - Echo to the active window socket details
  14. ; Both switches are optional
  15.  
  16. ;================================================================================== ALIASES
  17.  
  18. alias getfile {
  19. if (-re == $1 || -er == $1) { %_run = yes | %_echo = yes | tokenize 32 $2- }
  20. if (-r == $1) { %_run = yes | tokenize 32 $2- }
  21. if (-e == $1) { %_echo = yes | tokenize 32 $2- }
  22.  
  23. if (!$1) { echo $color(info) -ta * [FILE] No local directory specified! | return }
  24. if (!$2) { echo $color(info) -ta * [FILE] No site specified! | return }
  25. if (" !isin $1-) { echo $color(info) -ta * [FILE] No Quotes present in local download directory! | return }
  26. var %a = $gettok($1-,-1,32)
  27. if (www.* !iswm %a && https://* !iswm %a && http://* !iswm %a) { echo $color(info) -ta * [FILE] No valid website specified! | return }
  28.  
  29. %_site = $gettok($1-,-1,32)
  30. %_file = $qt($remove($1-,%_site,"))
  31. %_host = $gettok($remove(%_site,https://,https://,www.),1,47)
  32.  
  33. var %a = $nofile(%_file)
  34. if (!$isdir(%a)) { mkdir %a }
  35. if ($isfile(%_file)) { .remove %_file }
  36.  
  37. write -c %_file
  38. sockclose file
  39. if (https://* iswm %_site) { sockopen -e46 file %_host 443 }
  40. else { sockopen file %_host 80 }
  41. if (%_echo == yes) { %_start = $ctime | echo $color(info) -tag * [FILE] Opening socket... }
  42. }
  43.  
  44. alias -l unsetit { unset %_site %_file %_host %_run %_echo %_start %_content }
  45.  
  46. alias -l enddownload {
  47. if (%_echo == yes) { echo $color(info) -tag * [FILE] $nopath($remove(%_file,")) file download complete... ( $+ $remove($bytes($file(%_file).size).suf,$chr(32)) $+ , $remove($replace($duration($calc($ctime - %_start)),wks,w,wk,w,days,d,day,d,hrs,h,hr,h,mins,m,min,m,secs,s,sec,s),$chr(32)) elapsed) }
  48. if (%_content == text/plain) {
  49. var %a = $read(%_file,0)
  50. if (%a isalnum || %a isnum) { write -dl0 %_file }
  51. var %a = $read(%_file,1)
  52. if (%a isalnum || %a isnum) { write -dl1 %_file }
  53. var %a = $read(%_file,$calc($lines(%_file) - 1))
  54. if (%a == 0) { write $+(-dl,$readn) %_file }
  55. var %a = $read(%_file,$lines(%_file))
  56. if (%a == $null) { write $+(-dl,$lines(%_file)) %_file }
  57. }
  58. if (%_run == yes) { run %_file }
  59. unsetit
  60. }
  61.  
  62. ;================================================================================== SOCKET EVENTS
  63.  
  64. on *:sockopen:file:{
  65. if ($sockerr) { if (%_echo == yes) { echo $color(info) -tag * [FILE] Socket open errors... } | unsetit | return }
  66. if (%_echo == yes) { echo $color(info) -tag * [FILE] Reading socket... }
  67. sockwrite -n file GET %_site HTTP/1.1
  68. sockwrite -n file Host: %_host
  69. sockwrite -n file User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
  70. sockwrite -n file $str($crlf,2)
  71. }
  72. on *:sockread:file:{
  73. if ($sockerr) { if (%_echo == yes) { echo $color(info) -tag * [FILE] Socket read errors... } | unsetit | return }
  74. elseif (!$sock($sockname).mark) { var %read | sockread %read | if (Content-Type: * iswm %read) { %_content = $remove($gettok(%read,2,32),;,") } | if (%read == $null) { sockmark $sockname 1 } }
  75. else { sockread &image | if (%_file) { bwrite $qt(%_file) -1 -1 &image } | .timerechoget -o 1 1 enddownload }
  76. }
  77.  
  78. ;================================================================================== EOF
  79.  


Comments (2)
February 12th, 2020 - By: westor
Admin
Some comments about the 1.0 release:

/sockopen -e46 , the -46 is not need there.

$gettok($1,1--2,92 , you can use $gettok($1,1-2,92)

.remove $1 , you have to use $qt() like .remove $qt($1) , also if path have spaces it will not work.

in every write -dlN %variable you need to use $qt() there to like write -dl0 $qt(%_file)

run %_file , you have to use $qt() there too, like run $qt(%_file)

in bwrite %_file ... , you have to use $qt() there too, like bwrite $qt(%_file) ....
February 12th, 2020 - By: westor
Admin
Also it would be good if you could add more examples and a better alias description of what is the purpose so the new users will understand better

Login to Comment.