# How to get rpm file with ruby?

**URL:** <https://www.ruby-forum.com/t/how-to-get-rpm-file-with-ruby/196033>\
**Category:** Ruby\
**Created:** [October 5, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/how-to-get-rpm-file-with-ruby/196033 "2010-10-05T21:20:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [October 5, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/how-to-get-rpm-file-with-ruby/196033/1 "2010-10-05T21:20:58Z")

</div>

Neither of the methods below are able to download this rpm file. If  
you use firefox it works fine, how can I do this in ruby as part of a  
install script I am trying to write in ruby ?

* * *

require ‘net/http’

Net::HTTP.start(“apt.sw.be”) { |http|  
resp = http.get(“/redhat/el5/en/x86\_64/rpmforge/RPMS//rpmforge-  
release-0.3.6-1.el5.rf.x86\_64.rpm”)  
open(“postgis.rpm”, “wb”) { |file|  
file.write(resp.body)  
}  
}

##########################

open(‘[http://apt.sw.be/redhat/el5/en/x86\_64/rpmforge/RPMS/rpmforge-](http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-)  
release-0.3.6-1.el5.rf.x86\_64.rpm’)

---

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [October 5, 2010, 10:38pm UTC](https://www.ruby-forum.com/t/how-to-get-rpm-file-with-ruby/196033/2 "2010-10-05T22:38:33Z")

</div>

Jedrin wrote:

> Neither of the methods below are able to download this rpm file.

Please post the exact error message you see (or other symptom - e.g.  
does it hang? do you see a zero-byte file? something else?)

It looks all right to me. In irb:

> > require ‘net/http’  
> > =\> true
> 
> > resp = Net::HTTP.start(“apt.sw.be”) { |http| http.get("/redhat/el5/en/x86\_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86\_64.rpm") }  
> > =\> #\<Net::HTTPOK 200 OK readbody=true\>
> 
> > resp.body.size  
> > =\> 16697
> 
> > resp[‘Content-Type’]  
> > =\> “application/x-redhat-package-manager”
> 
> > RUBY\_DESCRIPTION  
> > =\> “ruby 1.8.7 (2010-01-10 patchlevel 249) [x86\_64-linux]”

Perhaps you are behind a proxy or something, and you have firefox  
configured to use that proxy?
