[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to download a file ?

pere.noel

7/1/2006 8:32:00 AM

i'd like to know how to download a compressed file (4 to 15 mb) with
ruby, and how to choose the folder to receive it ???

--
une bévue
3 Answers

Jeff Schwab

7/1/2006 12:28:00 PM

0

Une bévue wrote:
> i'd like to know how to download a compressed file (4 to 15 mb) with
> ruby, and how to choose the folder to receive it ???

require 'open-uri'

url = 'http://groups.google.com/group/comp.lang.ruby/tree/browse... +
'thread/6db927bc86697398/f3cd16a2b541528c?rnum=1&_done=' +
'%2Fgroup%2Fcomp.lang.ruby%2Fbrowse_frm%2Fthread%2F6db9' +
'27bc86697398%2Ff3cd16a2b541528c%3F#doc_f3cd16a2b541528c'

open("myfile.html", 'w') do |dst|
open(url) do |src|
dst.write(src.read)
end
end

Kenosis

7/3/2006 8:11:00 PM

0

Might also be a good use of Rio (search this group for info on Rio.)

Ken

Jeffrey Schwab wrote:
> Une bévue wrote:
> > i'd like to know how to download a compressed file (4 to 15 mb) with
> > ruby, and how to choose the folder to receive it ???
>
> require 'open-uri'
>
> url = 'http://groups.google.com/group/comp.lang.ruby/tree/browse... +
> 'thread/6db927bc86697398/f3cd16a2b541528c?rnum=1&_done=' +
> '%2Fgroup%2Fcomp.lang.ruby%2Fbrowse_frm%2Fthread%2F6db9' +
> '27bc86697398%2Ff3cd16a2b541528c%3F#doc_f3cd16a2b541528c'
>
> open("myfile.html", 'w') do |dst|
> open(url) do |src|
> dst.write(src.read)
> end
> end

rio4ruby

7/14/2006 5:29:00 PM

0

To follow up on the excellent suggestion by Kenosis ;) Here is how
Rio's copy-to operator could be used to download a file.

require 'rio'

rio(url) > rio('output_dir')

The post mentions that the file is compressed. If it is a gzipped file
and one wished to have an uncompressed local copy, something like the
following could be used.

rio(url_of_gzipped_file).gzip > rio('output_dir')


Cheers
-Christopher


Kenosis wrote:
> Might also be a good use of Rio (search this group for info on Rio.)
>
> Ken
>
> Jeffrey Schwab wrote:
> > Une bévue wrote:
> > > i'd like to know how to download a compressed file (4 to 15 mb) with
> > > ruby, and how to choose the folder to receive it ???
> >
> > require 'open-uri'
> >
> > url = 'http://groups.google.com/group/comp.lang.ruby/tree/browse... +
> > 'thread/6db927bc86697398/f3cd16a2b541528c?rnum=1&_done=' +
> > '%2Fgroup%2Fcomp.lang.ruby%2Fbrowse_frm%2Fthread%2F6db9' +
> > '27bc86697398%2Ff3cd16a2b541528c%3F#doc_f3cd16a2b541528c'
> >
> > open("myfile.html", 'w') do |dst|
> > open(url) do |src|
> > dst.write(src.read)
> > end
> > end