Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to download file from web site

Reply
Thread Tools

How to download file from web site

 
 
Timothy Hunter
Guest
Posts: n/a
 
      03-03-2007
Okay, it's easy to download a file from an FTP server with Net::FTP.
Given a URL like this:
"http://rubyforge.org/frs/download.php/17670/RMagick-1.15.3.tar.gz" is
there a way using pure Ruby to download this file?

 
Reply With Quote
 
 
 
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      03-03-2007
On Sat, 3 Mar 2007, Timothy Hunter wrote:

> Okay, it's easy to download a file from an FTP server with Net::FTP. Given a
> URL like this:
> "http://rubyforge.org/frs/download.php/17670/RMagick-1.15.3.tar.gz" is there
> a way using pure Ruby to download this file?
>


harp:~ > cat a.rb
require 'open-uri'
uri = 'http://rubyforge.org/frs/download.php/17670/RMagick-1.15.3.tar.gz'

open(uri) do |fin|
open(File.basename(uri), 'w') do |fout|
while(buf = fin.read(8192))
fout.write buf
end
end
end

harp:~ > ruby a.rb

harp:~ > new RMagick-1.15.3.tar.gz
-rw-rw-r-- 1 ahoward ahoward 1048764 Mar 3 08:00 RMagick-1.15.3.tar.gz


-a
--
be kind whenever possible... it is always possible.
- the dalai lama

 
Reply With Quote
 
 
 
 
Timothy Hunter
Guest
Posts: n/a
 
      03-03-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Sat, 3 Mar 2007, Timothy Hunter wrote:
>
>> Okay, it's easy to download a file from an FTP server with Net::FTP.
>> Given a URL like this:
>> "http://rubyforge.org/frs/download.php/17670/RMagick-1.15.3.tar.gz"
>> is there a way using pure Ruby to download this file?
>>

>
> harp:~ > cat a.rb
> require 'open-uri'
> uri = 'http://rubyforge.org/frs/download.php/17670/RMagick-1.15.3.tar.gz'
>
> open(uri) do |fin|
> open(File.basename(uri), 'w') do |fout|
> while(buf = fin.read(8192))
> fout.write buf
> end
> end
> end
>
> harp:~ > ruby a.rb
>
> harp:~ > new RMagick-1.15.3.tar.gz
> -rw-rw-r-- 1 ahoward ahoward 1048764 Mar 3 08:00
> RMagick-1.15.3.tar.gz
>
>
> -a

Thanks again, Ara!

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      03-03-2007
On 03.03.2007 15:47, Timothy Hunter wrote:
> Okay, it's easy to download a file from an FTP server with Net::FTP.
> Given a URL like this:
> "http://rubyforge.org/frs/download.php/17670/RMagick-1.15.3.tar.gz" is
> there a way using pure Ruby to download this file?


You might be surprised to learn that there is also Net::HTTP...

http://www.ruby-doc.org/stdlib/libdo...doc/index.html

And then there's open-uri

http://www.ruby-doc.org/stdlib/libdo...doc/index.html

robert
 
Reply With Quote
 
ara.t.howard@noaa.gov
Guest
Posts: n/a
 
      03-03-2007
On Sun, 4 Mar 2007, Timothy Hunter wrote:

>>
>> -a

> Thanks again, Ara!
>


no way - thank you! i'm preparing a class right now, here's one of many
examples i've got put together:


#
# gem install RMagick @ http://rmagick.rubyforge.org/
#
require "rubygems"
require "RMagick"
#
# converts all images named on the command-line into thumbnails
#
ARGV.each do |path|
path = File.expand_path path
dirname, basename = File.split path
base, ext = basename.split %r/[.]/, 2

img = Magick::ImageList.new path

thumb = img.thumbnail 96, 96
thumb_path = File.join dirname, "#{ base }.thumb.#{ ext }"
thumb.write thumb_path

puts thumb_path
end



thanks for rmagick.

-a
--
be kind whenever possible... it is always possible.
- the dalai lama

 
Reply With Quote
 
Timothy Hunter
Guest
Posts: n/a
 
      03-03-2007
(E-Mail Removed) wrote:
> On Sun, 4 Mar 2007, Timothy Hunter wrote:
>
>>>
>>> -a

>> Thanks again, Ara!
>>

>
> no way - thank you! i'm preparing a class right now, here's one of many
> examples i've got put together:
>
>
> #
> # gem install RMagick @ http://rmagick.rubyforge.org/
> #
> require "rubygems"
> require "RMagick"
> #
> # converts all images named on the command-line into thumbnails
> #
> ARGV.each do |path|
> path = File.expand_path path
> dirname, basename = File.split path
> base, ext = basename.split %r/[.]/, 2
>
> img = Magick::ImageList.new path
>
> thumb = img.thumbnail 96, 96
> thumb_path = File.join dirname, "#{ base }.thumb.#{ ext }"
> thumb.write thumb_path
>
> puts thumb_path
> end
>
>
>
> thanks for rmagick.
>
> -a

You're welcome!

The reason I'm asking these questions is because I'm working on a Ruby
program to download and install ImageMagick, all its delegate libraries,
and RMagick, on OS X, starting from scratch and not using MacPorts.

BTW, I saw your comment about the rmagick gem. You're right, it's
screwy. I'm hoping to mothball it in RMagick 2.0.0, if I can figure out
a way to replace my autoconf-generated configure script with pure Ruby.

 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      03-03-2007
On Mar 3, 2007, at 9:39 AM, Timothy Hunter wrote:

> The reason I'm asking these questions is because I'm working on a
> Ruby program to download and install ImageMagick, all its delegate
> libraries, and RMagick, on OS X, starting from scratch and not
> using MacPorts.


I just spent about a day fixing my RMagick install (on Mac OS X),
that had become horribly broken, so releasing something like this
would make you a hero in my eyes.

James Edward Gray II

 
Reply With Quote
 
Timothy Hunter
Guest
Posts: n/a
 
      03-03-2007
James Edward Gray II wrote:
> On Mar 3, 2007, at 9:39 AM, Timothy Hunter wrote:
>
>> The reason I'm asking these questions is because I'm working on a
>> Ruby program to download and install ImageMagick, all its delegate
>> libraries, and RMagick, on OS X, starting from scratch and not using
>> MacPorts.

>
> I just spent about a day fixing my RMagick install (on Mac OS X), that
> had become horribly broken, so releasing something like this would
> make you a hero in my eyes.
>
> James Edward Gray II
>

Ouch! Sorry you had trouble. Email me when you have a problem, James.
I'll be glad to do what I can to help.

BTW, just last week I updated my "Installing RMagick on OS X HOWTO"
here: http://rmagick.rubyforge.org/install-osx.html. I guess it's too
late to help you but maybe it'll help somebody else.

 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      03-03-2007
On Mar 3, 2007, at 11:53 AM, Timothy Hunter wrote:

> James Edward Gray II wrote:
>> On Mar 3, 2007, at 9:39 AM, Timothy Hunter wrote:
>>
>>> The reason I'm asking these questions is because I'm working on a
>>> Ruby program to download and install ImageMagick, all its
>>> delegate libraries, and RMagick, on OS X, starting from scratch
>>> and not using MacPorts.

>>
>> I just spent about a day fixing my RMagick install (on Mac OS X),
>> that had become horribly broken, so releasing something like this
>> would make you a hero in my eyes.
>>
>> James Edward Gray II
>>

> Ouch! Sorry you had trouble. Email me when you have a problem,
> James. I'll be glad to do what I can to help.


No worries. It wasn't your fault. I broke it.

James Edward Gray II

 
Reply With Quote
 
Ezra Zygmuntowicz
Guest
Posts: n/a
 
      03-04-2007

On Mar 3, 2007, at 9:53 AM, Timothy Hunter wrote:

> James Edward Gray II wrote:
>> On Mar 3, 2007, at 9:39 AM, Timothy Hunter wrote:
>>
>>> The reason I'm asking these questions is because I'm working on a
>>> Ruby program to download and install ImageMagick, all its
>>> delegate libraries, and RMagick, on OS X, starting from scratch
>>> and not using MacPorts.

>>
>> I just spent about a day fixing my RMagick install (on Mac OS X),
>> that had become horribly broken, so releasing something like this
>> would make you a hero in my eyes.
>>
>> James Edward Gray II
>>

> Ouch! Sorry you had trouble. Email me when you have a problem,
> James. I'll be glad to do what I can to help.
>
> BTW, just last week I updated my "Installing RMagick on OS X HOWTO"
> here: http://rmagick.rubyforge.org/install-osx.html. I guess it's
> too late to help you but maybe it'll help somebody else.
>


Here is a shell script I wrote a while ago to build ruby/imagemagick/
rmagick on OSX without using macports. Feel free to use it if you want.

#!/bin/sh

# Install Ruby & IMageMagick & RMagick on Macintosh OS X 10.4.7 (Intel)
# Stock Apple Developer Tools (2.3)

# Readline
READLINE_VERSION="5.1"
wget ftp://ftp.gnu.org/gnu/readline/readline-${READLINE_VERSION}.tar.gz
tar xzvf readline-${READLINE_VERSION}.tar.gz
pushd readline-${READLINE_VERSION}
/configure --prefix=/usr/local
make
sudo make install
popd


# Ruby

RUBY_VERSION="1.8.5"

wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-${RUBY_VERSION}.tar.gz
tar xfz ruby-${RUBY_VERSION}.tar.gz

pushd ruby-${RUBY_VERSION}
/configure
make
sudo make install
popd

# Ruby Gems

GEM_VERSION="0.9.2"

wget http://rubyforge.org/frs/download.php/11289/rubygems-$
{GEM_VERSION}.tgz
tar xfz rubygems-${GEM_VERSION}.tgz

pushd rubygems-${GEM_VERSION}
sudo ruby setup.rb
popd

# ImageMagick

LPNG_VERSION="1.2.12"

wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$
{LPNG_VERSION}.tar.gz
tar xfz libpng-${LPNG_VERSION}.tar.gz

pushd libpng-${LPNG_VERSION}
/configure
make
sudo make install
popd

JPEG_VERSION="6b"

wget http://www.ijg.org/files/jpegsrc.v${JPEG_VERSION}.tar.gz
tar xfz jpegsrc.v${JPEG_VERSION}.tar.gz

pushd jpeg-${JPEG_VERSION}
/configure
make
sudo make install
sudo make install-lib
popd

TIFF_VERSION="3.8.2"

wget ftp://ftp.remotesensing.org/pub/libtiff/tiff-${TIFF_VERSION}.tar.gz
tar xfz tiff-${TIFF_VERSION}.tar.gz

pushd tiff-${TIFF_VERSION}
/configure
make
sudo make install
popd

IM_VERSION_MAJOR="6.2.9"
IM_VERSION_MINOR="4"

IM_VERSION="${IM_VERSION_MAJOR}-${IM_VERSION_MINOR}"

wget ftp://ftp.imagemagick.net/pub/ImageMagick/ImageMagick-$
{IM_VERSION}.tar.gz
tar xfz ImageMagick-${IM_VERSION}.tar.gz

pushd ImageMagick-${IM_VERSION_MAJOR}
/configure
make
sudo make install
popd


sudo gem install rmagick


Cheers-

-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- (E-Mail Removed)
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
List of free web site design, web site backgrounds, web site layoutsresources cyber XML 1 12-25-2007 11:48 PM
Free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-24-2007 04:26 PM
List of free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-21-2007 03:47 PM
List of free web site design, web site backgrounds, web site layoutsweb sites cyber HTML 1 12-19-2007 09:07 AM



Advertisments