Forum: Ruby Downloading a file using ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
16f82f5caa12038965397b3fd6ca3bec?d=identicon&s=25 ruby learner (idealone)
on 2009-04-07 10:49
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
883ee4d990ef9e57a79b5b0ff3b66241?d=identicon&s=25 bwv549 (Guest)
on 2009-04-07 23:35
(Received via mailing list)
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
883ee4d990ef9e57a79b5b0ff3b66241?d=identicon&s=25 bwv549 (Guest)
on 2009-04-07 23:36
(Received via mailing list)
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
16f82f5caa12038965397b3fd6ca3bec?d=identicon&s=25 ruby learner (idealone)
on 2009-04-08 15:14
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.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
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2009-04-08 15:27
(Received via mailing list)
On Wed, Apr 8, 2009 at 9:14 AM, Idealone Ideally <shekarls@gmail.com>
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
This topic is locked and can not be replied to.