Downloading a file using ruby

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:

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)
}
}

   Please let me know if i could use similar technique to download a

file(excel file).

Thanks

  I

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

require ‘open-uri’
open(“someplace.com”) do |in_io|
File.open(“somefile.mp3”, ‘w’) do |out_io|
out_io.print in_io.read
end
end

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

On Wed, Apr 8, 2009 at 9:14 AM, Idealone I. [email protected]
wrote:


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/ftpurl.html


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

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(“someplace.com”) 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