mIRC Home    About    Download    Register    News    Help

Print Thread
#224917 21/08/10 09:08 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Hi all,

Just wondering if anyone could give me pointers on how I would go about downloading say a ".mrc" file from a web server. I am aware that I would prob need to use binary variables etc, but unsure how to go about this.

Any help would be greatly appreciated.



Newbie
HaleyJ #224921 21/08/10 11:07 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Let's say you wanted to get www.website.com/file.mrc, you would do it like this:

Code:
alias getmrc sockopen getmrc website.com 80
on *:sockopen:getmrc:{ 
  var %s = sockwrite -n getmrc
  %s GET /file.mrc HTTP/1.1
  %s Host: website.com
  %s Accept: */*
  %s Connection: close
  %s 
}
on *:sockread:getmrc:{
  var %data
  sockread %data
  if (%data) write file.mrc $v1
}


The above code will save the file in your mIRC directory, you need to change the filepath in the /write command in the sockread event if you want to save it elsewhere.

You should be able to modify this to meet your needs smile

hixxy #224934 22/08/10 08:36 AM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Hi hixxy,

Thank you for your reply. I should be able to easily work with what you gave me.

My only question is, if the file is really large, is there a quicker/more efficient way to do this using binary variables?

Thank you again.


Newbie
hixxy #224936 22/08/10 10:50 AM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Hi hixxy,

I got it working. Thanks for your help.

Any idea how I would take out the headers and just download the scriptfile itself?

thanks


Newbie
HaleyJ #224945 22/08/10 01:39 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
alias getmrc sockopen getmrc website.com 80
on *:sockopen:getmrc:{ 
  var %s = sockwrite -n getmrc
  %s GET /file.mrc HTTP/1.1
  %s Host: website.com
  %s Accept: */*
  %s Connection: close
  %s 
}
on *:sockread:getmrc:{
  var %data
  sockread %data
  if (!%data) {
    sockread 8192 &data
    while ($sockbr) {
      bwrite file.mrc -1 -1 &data
      sockread -f &data
    }
  }
}


That should answer both of your questions smile

Bare in mind that the above script doesn't do error checking of any kind and assumes everything will just work. If you're going to accept a script file to download from a user input, you will need to add some error checks.

hixxy #224946 22/08/10 04:33 PM
Joined: Jul 2006
Posts: 242
H
HaleyJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
H
Joined: Jul 2006
Posts: 242
Hello Again,

Thanks for your reply.

Unfortunetly your amended script only downloads a third of the file.



Newbie

Link Copied to Clipboard