[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Downloading a file using ruby

Idealone Ideally

4/7/2009 8:49:00 AM

Hi All,
I want to download a file from my web application using/calling
ruby code.
Manually i can download reports by clicking on 'DOWNLOAD' button in my
app, which in turn gets the file from servlet path(where the files are
stored).
My question is, how can i automate this download part in ruby, if its
feasible.
During my googling, i found a set of ruby code to download pictures
from a site.

snippet of the code looks like this:
<CODE>
require 'net/http'

Net::HTTP.start("static.test.com") { |http|
resp = http.get("/92/2134322cedc5fef7_o.jpg")
open("fun.jpg", "wb") { |file|
file.write(resp.body)
}
}
<CODE>

Please let me know if i could use similar technique to download a
file(excel file).

Thanks

I
--
Posted via http://www.ruby-....

4 Answers

bwv549

4/7/2009 9:30:00 PM

0

require 'open-uri'

open("http://localhost/jtprince/TRASH.TRASH") do |io|
data = io.read
end

Are you looking for something like that? This works on my own machine
to grab files under the web server.

--John

bwv549

4/7/2009 9:33:00 PM

0

yes, this should download any kind of file (including excel). I use
it to read/write mp3 files from online:

require 'open-uri'
open("http://someplace.com/somefile...) do |in_io|
File.open("somefile.mp3", 'w') do |out_io|
out_io.print in_io.read
end
end

Idealone Ideally

4/8/2009 1:15:00 PM

0

bwv549 wrote:
> yes, this should download any kind of file (including excel). I use
> it to read/write mp3 files from online:
>
> require 'open-uri'
> open("http://someplace.com/somefile...) do |in_io|
> File.open("somefile.mp3", 'w') do |out_io|
> out_io.print in_io.read
> end
> end

----------------------------------------------------------------

Thanks guys for the reply.
Actually i had mistaken that the download picks the file from web
server, but after talking to my developers i realized that they are
internally getting the file using ftp.
I wanted to know how can i "pull a file from ftp". Is there any ruby
library to pull or push files through "ftp"

Cheers
--
Posted via http://www.ruby-....

Rick DeNatale

4/8/2009 1:26:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Wed, Apr 8, 2009 at 9:14 AM, Idealone Ideally <shekarls@gmail.com> wrote:

> bwv549 wrote:
> > yes, this should download any kind of file (including excel). I use
> > it to read/write mp3 files from online:
> >
> > require 'open-uri'
> > open("http://someplace.com/somefile...) do |in_io|
> > File.open("somefile.mp3", 'w') do |out_io|
> > out_io.print in_io.read
> > end
> > end
>
> ----------------------------------------------------------------
>
> Thanks guys for the reply.
> Actually i had mistaken that the download picks the file from web
> server, but after talking to my developers i realized that they are
> internally getting the file using ftp.
> I wanted to know how can i "pull a file from ftp". Is there any ruby
> library to pull or push files through "ftp"
>
>
Open-uri also works with ftp uri's
http://www.cs.tut.fi/~jkorpela/f...


--
Rick DeNatale

Blog: http://talklikeaduck.denh...
Twitter: http://twitter.com/Ri...
WWR: http://www.workingwithrails.com/person/9021-ric...
LinkedIn: http://www.linkedin.com/in/ri...