Downloading a file using ruby

  • Thread starter Idealone Ideally
  • Start date
I

Idealone Ideally

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
 
B

bwv549

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.mp3") do |in_io|
File.open("somefile.mp3", 'w') do |out_io|
out_io.print in_io.read
end
end
 
I

Idealone Ideally

bwv549 said:
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.mp3") 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
 
R

Rick DeNatale

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

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top