tglogo.png

Downloading File

Filename: /download
/*
**
** /download by hixxy ([email protected]) for mIRC 6.17 or above.
**
**
** What the script does
** ��������������������
**
** This script will let you download files from the internet using mIRC.
**
** To use some one of the script's features you will need to install SSL for mIRC.
** For help installing OpenSSL please take a look at this page: http://www.mirc.co.uk/ssl.html
**
** How to load
** �����������
**
** You can load this script by typing /load -rs <path to download.mrc>. If you saved the file in your mIRC directory you can just do /load -rs download.mrc
** You can also just copy/paste it into remote from a website and then hit the OK button.
**
** How to use
** ����������
**
** NOTE: You can use this to download from either HTTP or FTP servers.
**
** The syntax is one of the following.
** /download <-cpr> <name>
** /download [-eo] <name> <url> <file>
**
** The -cpr switches stand for cancel, pause and resume respectively. You can only use these on existing downloads.
**
** The -e switch means you want to create an SSL socket.
** The -o switch means you want to overwrite <file> if it exists rather than spitting out an error.
**
** The script files off various signals as it is downloading the file. These are all sent to the 'download' signal with parameters being:
**
** begin - when the download begins.
** cancel - when the download is cancelled.
** end - when the download finishes.
** error <error code> <error message> - when there's a socket error.
** notfound <file> - could not find the requested file.
** pause - when the download is paused.
** progress <size> - when the snippet has downloaded another chunk of the file. <size> is the amount of bytes downloaded.
** resume - when the download is resumed.
** size <size> - the size of the file has been acquired.
**
** FTP only signals:
**
** cannotassignaddress - the server sent a 425 error.
** requireslogin - the server does not allow anonymous access.
**
** Contact
** �������
**
** If you have a feature suggestion, bug report or question, please send an email to [email protected]
** If you got the script from a scripting website and I (hixxy) submitted the code, you may also leave feedback on the script's comment page.
**
*/

alias -l raisemessage {
  if ($line($active,0)) && (($show) || ($1 == -e)) { linesep -a }
  echo $colour(info) -a $+ $iif($1 != -e,q $1-,$chr(32) $2-)
  if ($show) || ($1 == -e) { linesep -a }
  halt
}

alias download {
  var %overwrite, %ssl
  if ($isid) { raisemessage -e * /download: Should be called as a command }
  if ($0 < 3) && (!$istok(-c -p -r,$1,32)) { raisemessage -e * /download: Insufficient parameters }
  if (-* iswm $1) {
    if ((c isincs $1) || (p isincs $1) || (r isincs $1)) && (!$sock(download_ $+ $2)) { raisemessage -e * /download: No such download ' $+ $2' }
    if (c isincs $1) {
      if ($isfile($gettok($sock(download_ $+ $2).mark,3-,32))) { .remove $qt($gettok($sock(download_ $+ $2).mark,3-,32)) }
      if (http:* iswm $gettok($sock(download_ $+ $2).mark,2,32)) {
        sockclose download_ $+ $2
        .signal download $2 cancel
        raisemessage * /download: Cancelled download ' $+ $2'
      }
      elseif (ftp:* iswm $gettok($sock(download_ $+ $2).mark,2,32)) {
        sockclose download_ $+ $2
        sockclose ftp_download_ $+ $2
        sockclose ftpc_download_ $+ $2
        .signal download $2 cancel
        raisemessage * /download: Cancelled download ' $+ $2'
      }
    }
    elseif (p isincs $1) {
      if (http:* iswm $gettok($sock(download_ $+ $2).mark,2,32)) && (!$sock(download_ $+ $2).pause) {
        sockpause download_ $+ $2
        .signal download $2 pause
        raisemessage * /download: Paused download ' $+ $2'
      }
      elseif (ftp:* iswm $gettok($sock(download_ $+ $2).mark,2,32)) && (!$sock(download_ $+ $2).pause) {
        sockpause download_ $+ $2
        if ($sock(ftpc_download_ $+ $2)) { sockpause ftpc_download_ $+ $2 }
        .signal download $2 pause
        raisemessage * /download: Paused download ' $+ $2'
      }
    }
    elseif (r isincs $1) {
      if (http:* iswm $gettok($sock(download_ $+ $2).mark,2,32)) && ($sock(download_ $+ $2).pause) {
        sockpause -r download_ $+ $2
        .signal download $2 resume
        raisemessage * /download: Resumed download ' $+ $2'
      }
      elseif (ftp:* iswm $gettok($sock(download_ $+ $2).mark,2,32)) && ($sock(download_ $+ $2).pause) {
        sockpause -r download_ $+ $2
        if ($sock(ftpc_download_ $+ $2)) { sockpause -r ftpc_download_ $+ $2 }
        .signal download $2 resume
        raisemessage * /download: Resumed download ' $+ $2'
      }
    }
    if (e isincs $1) { var %ssl = $true }
    if (o isincs $1) { var %overwrite = $true }
    tokenize 32 $2-
  }
  if ($sock(download_ $+ $1)) { raisemessage -e * /download: Download exists ' $+ $1' }
  if ($isfile($3-)) && (!%overwrite) { raisemessage -e * /download: File exists ' $+ $3-' }
  if ($nopath($3-) == $null) { raisemessage -e * /download: No filename supplied ' $+ $3-' }
  if ($nofile($3-) $+ $mkfn($nopath($3-)) != $3-) { raisemessage -e * /download: Filename not valid $+(',$nopath($3-),') }
  if (%ssl) && (!$sslready) { raisemessage -e * /download: SSL not ready }
  if (http:* !iswm $2) && (ftp:* !iswm $2) { raisemessage -e * /download: Invalid URL }
  var %port = $iif(http:* iswm $2,80,21)
  while (!$portfree(%port)) { inc %port }
  sockopen $iif(%ssl == $true,-e) download_ $+ $1 $gettok($2,2,47) %port
  sockmark download_ $+ $1 $false $2-
  raisemessage * /download: Downloading $2 to $3-
}

on *:sockopen:download_*:{
  if ($sockerr) {
    .signal download $mid($sockname,10) error $sock($sockname).wserr $sock($sockname).wsmsg
    return
  }
  if (http:* iswm $gettok($sock($sockname).mark,2,32)) {
    sockwrite -n $sockname GET / $+ $gettok($gettok($sock($sockname).mark,2,32),3-,47) HTTP/1.1
    sockwrite -n $sockname Host: $gettok($gettok($sock($sockname).mark,2,32),2,47)
    sockwrite -n $sockname Accept: */*
    sockwrite -n $sockname Connection: close
    sockwrite -n $sockname User-Agent: mIRC/ $+ $version
    sockwrite -n $sockname
  }
}
on *:sockread:download_*:{
  if (http:* iswm $gettok($sock($sockname).mark,2,32)) {
    if ($gettok($sock($sockname).mark,1,32) == $false) {
      var %data
      sockread %data
      if (*404 not found* iswm %data) {
        .signal download $mid($sockname,10) notfound / $+ $gettok($gettok($sock($sockname).mark,2,32),3-,47)
        sockclose $sockname
        return
      }
      if (%data == $null) {
        sockmark $sockname $true $gettok($sock($sockname).mark,2-,32)
        .signal download $mid($sockname,10) begin
      }
      elseif (content-length: * iswm %data) { .signal download $mid($sockname,10) size $gettok(%data,2,32) }
    }
    else {
      sockread -f &data
      bwrite $qt($gettok($sock($sockname).mark,3-,32)) -1 -1 &data
      .signal download $mid($sockname,10) progress $sockbr
    }
  }
  else {
    var %data
    sockread %data
    tokenize 32 %data
    if ($1 == 150) { .signal download $mid($sockname,10) size $mid($gettok($1-,-2,32),2,-1) }
    elseif ($1-2 == 200 PORT) { sockwrite -n $sockname TYPE I }
    elseif ($1-2 == 200 TYPE) { sockwrite -n $sockname RETR $gettok($gettok($sock($sockname).mark,2,32),-1,47) }
    elseif ($1 == 220) { sockwrite -n $sockname USER anonymous }
    elseif ($1 == 226) {
      .signal download $mid($sockname,10) end
      sockclose $sockname
      sockclose ftp_ $+ $sockname
      sockclose ftpc_ $+ $sockname
    }
    elseif ($1 == 230) {
      if ($deltok($gettok($gettok($sock($sockname).mark,2,32),3-,47),-1,47) != $null) { sockwrite -n $sockname CWD / $+ $v1 }
    }
    elseif ($1 == 250) {
      socklisten ftp_download_ $+ $mid($sockname,10) 3762
      sockmark ftp_download_ $+ $mid($sockname,10) $sock($sockname).mark
      sockwrite -n $sockname PORT $replace($sock(ftp_download_ $+ $mid($sockname,10)).ip,.,$chr(44)) $+ ,14,178
    }
    elseif ($1 == 331) { sockwrite -n $sockname PASS ftpd }
    elseif ($1 == 425) {
      .signal download $mid($sockname,10) cannotassignaddress
      sockclose $sockname
    }
    elseif ($1 == 530) {
      .signal download $mid($sockname,10) requireslogin
      sockclose $sockname
    }
    elseif ($1 == 550) {
      .signal download $mid($sockname,10) notfound / $+ $gettok($gettok($sock($sockname).mark,2,32),3-,47)
      sockclose $sockname
    }
  }
}
on *:socklisten:ftp_download_*:{
  sockaccept ftpc_ $+ $mid($sockname,5)
  sockmark ftpc_ $+ $mid($sockname,5) $sock($sockname).mark
  .signal download $mid($sockname,14) begin
}
on *:sockclose:download_*:{ .signal download $mid($sockname,10) end }
on *:sockread:ftpc_*:{
  sockread -f &data
  while ($sockbr) {
    bwrite $qt($gettok($sock($sockname).mark,3-,32)) -1 -1 &data
    .signal download $mid($sockname,15) progress $sockbr
    sockread -f &data
  }
}

on *:load:{
  if ($version < 6.17) {
    !.echo -q $input(This script was created for mIRC version 6.17 or later $+ $chr(44) you are using $version,dho,Invalid version)
    .unload -rs $script
  }
}

Related Files

by modified by Chain�
by Spoofing

Please note that on our website we use cookies necessary for the functioning of our website, cookies that optimize the performance. To learn more about our cookies, how we use them and their benefits, please read our Cookie Policy.
I Understand