[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

My simple downloader doesn't work

WujcioL

7/30/2008 5:31:00 PM

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

Hello,

I'm learning Ruby for some time. Today I started to write simple code
which will download specified files from specified servers but it
doesn't work. It always showing me error 500 when code is going to
download file. This is code:

require 'net/ftp'
require 'net/http'

class Get

def initialize(resource)
if resource=~/http:\/\/|ftp:\/\//
@resource=resource
@status=0
@type = resource[0..1].to_s
end
end

def get
case (@type)
when "ht"
@sock = Net.HTTP.new(@resource)
@sock.getbinaryfile("index.html",1024)
when "ft"
index = (@resource[6..-1].index("/")+5)
last = (@resource.size - @resource.reverse.index("/")-1)
ftp = Net::FTP.new(@resource[6..index])
ftp.login
ftp.chdir(@resource[(index+2)..last])
ftp.get(@resource[(last+1)..-1] , @resource[(last+1)..-1])
ftp.close
end
end

end
get = Get.new("ftp://sunsite.icm.edu.pl/pub/Linux/...
slackware-12.0/CHECKSUMS.md5.asc")
get.get

--
My own blog (in polish) :
wujciol.yoyo.pl

9 Answers

Gregory Brown

7/30/2008 5:47:00 PM

0

On Wed, Jul 30, 2008 at 1:30 PM, Mateusz Tybura <wujciol@gmail.com> wrote:
> Hello,
>
> I'm learning Ruby for some time. Today I started to write simple code
> which will download specified files from specified servers but it
> doesn't work. It always showing me error 500 when code is going to
> download file. This is code:

I didn't find out why your code doesn't work, but using open-uri from
the stdlib works, and might be nicer:

>> require "open-uri"
=> true
>> puts open("ftp://anonymous:anon@sunsite.icm.edu.pl/pub/Linux/slackware/slackware-12.0/CHECKSUMS.md5.asc").read
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkiPY8sACgkQakRjwEAQIjOctwCggx3kItwUmkXNFmhUko2M9jxd
2v8AnjfTZFeZbJlQZ3Pb8UTtkbq3df8m
=lKsD
-----END PGP SIGNATURE-----

WujcioL

7/31/2008 7:28:00 AM

0

It still don't work:

> require 'open-uri'
> puts open("anonymous:anonymous@sunsite.icm.edu.pl/pub/Linux/slackware/slackware-12.0/CHECKSUMS.md5.asc").read
Net:FTPPermError: 500 Illegal PORT Command

I thinking about some bug in open-uri and net/ftp. Code is simple and
it runs so that's not mine error. Of course i succesfully downloaded
this file using Firefox3 and TotalCommander.
Code was tested on winXP and Kubuntu8.04.

Martin Boese

7/31/2008 8:48:00 AM

0

Maybe because active ftp and your firewall, try:

require 'open-uri'
open("ftp://whatever.ftp...., :ftp_active_mode => false).read

or with net/ftp call:
ftp.passive

martin

On Thursday 31 July 2008 08:29:15 WujcioL wrote:
> It still don't work:
> > require 'open-uri'
> > puts
> > open("anonymous:anonymous@sunsite.icm.edu.pl/pub/Linux/slackware/slackwar
> >e-12.0/CHECKSUMS.md5.asc").read
>
> Net:FTPPermError: 500 Illegal PORT Command
>
> I thinking about some bug in open-uri and net/ftp. Code is simple and
> it runs so that's not mine error. Of course i succesfully downloaded
> this file using Firefox3 and TotalCommander.
> Code was tested on winXP and Kubuntu8.04.



WujcioL

8/1/2008 9:56:00 AM

0

Martin Boese wrote:
> Maybe because active ftp and your firewall, try:
>
> require 'open-uri'
> open("ftp://whatever.ftp...., :ftp_active_mode => false).read
>
> or with net/ftp call:
> ftp.passive
>
> martin

There's no working firewall or ftp server on my host.
Your code with using 'open-uri' throws error unrecognized option:
ftp_active_mode (Argument Error)
--
Posted via http://www.ruby-....

Gregory Brown

8/1/2008 1:46:00 PM

0

On Thu, Jul 31, 2008 at 3:29 AM, WujcioL <WujcioL@gmail.com> wrote:
> It still don't work:
>
>> require 'open-uri'
>> puts open("anonymous:anonymous@sunsite.icm.edu.pl/pub/Linux/slackware/slackware-12.0/CHECKSUMS.md5.asc").read
> Net:FTPPermError: 500 Illegal PORT Command
>
> I thinking about some bug in open-uri and net/ftp. Code is simple and
> it runs so that's not mine error. Of course i succesfully downloaded
> this file using Firefox3 and TotalCommander.
> Code was tested on winXP and Kubuntu8.04.

The code I showed worked on my machine. Tested on OS X (10.4),
without any firewall issues.
Ruby version:

seltzer:~ sandal$ ruby -v
ruby 1.8.6 (2008-06-20 patchlevel 230) [i686-darwin8.11.1]



--
Killer Ruby PDF Generation named after a magnificent sea creature:
http://github.com/sa... | Non-tech stuff at:
http://metametta.bl...

Frederick Cheung

8/1/2008 1:54:00 PM

0


On 1 Aug 2008, at 14:46, Gregory Brown wrote:

> On Thu, Jul 31, 2008 at 3:29 AM, WujcioL <WujcioL@gmail.com> wrote:
>> It still don't work:
>>
>>> require 'open-uri'
>>> puts open("anonymous:anonymous@sunsite.icm.edu.pl/pub/Linux/
>>> slackware/slackware-12.0/CHECKSUMS.md5.asc").read
>> Net:FTPPermError: 500 Illegal PORT Command
>>
>> I thinking about some bug in open-uri and net/ftp. Code is simple and
>> it runs so that's not mine error. Of course i succesfully downloaded
>> this file using Firefox3 and TotalCommander.
>> Code was tested on winXP and Kubuntu8.04.
>
> The code I showed worked on my machine. Tested on OS X (10.4),
> without any firewall issues.
> Ruby version:
>
Beyond firewalls, active ftp won't work behind a NAT device.
Ftp servers sometimes say illegal port command if you tell them that
your address is a private ip address like 192.168.x (your address on
the network behind the nat device)

Fred
> seltzer:~ sandal$ ruby -v
> ruby 1.8.6 (2008-06-20 patchlevel 230) [i686-darwin8.11.1]
>
>
>
> --
> Killer Ruby PDF Generation named after a magnificent sea creature:
> http://github.com/sa... | Non-tech stuff at:
> http://metametta.bl...
>


WujcioL

8/1/2008 2:21:00 PM

0

Frederick Cheung wrote:
> On 1 Aug 2008, at 14:46, Gregory Brown wrote:
>
>>> this file using Firefox3 and TotalCommander.
>>> Code was tested on winXP and Kubuntu8.04.
>>
>> The code I showed worked on my machine. Tested on OS X (10.4),
>> without any firewall issues.
>> Ruby version:
>>
> Beyond firewalls, active ftp won't work behind a NAT device.
> Ftp servers sometimes say illegal port command if you tell them that
> your address is a private ip address like 192.168.x (your address on
> the network behind the nat device)
>
> Fred

It can be it cause i'm connecting from small LAN. Got any idea how to
make it works even that host is beheind nat device?
--
Posted via http://www.ruby-....

Frederick Cheung

8/1/2008 2:45:00 PM

0


On 1 Aug 2008, at 15:20, Mateusz Tybura wrote:

> Frederick Cheung wrote:
>> On 1 Aug 2008, at 14:46, Gregory Brown wrote:
>>
>>>> this file using Firefox3 and TotalCommander.
>>>> Code was tested on winXP and Kubuntu8.04.
>>>
>>> The code I showed worked on my machine. Tested on OS X (10.4),
>>> without any firewall issues.
>>> Ruby version:
>>>
>> Beyond firewalls, active ftp won't work behind a NAT device.
>> Ftp servers sometimes say illegal port command if you tell them that
>> your address is a private ip address like 192.168.x (your address on
>> the network behind the nat device)
>>
>> Fred
>
> It can be it cause i'm connecting from small LAN. Got any idea how to
> make it works even that host is beheind nat device?

You need to be using passive ftp. According to the docs you just need
to say ftp.passive = true (assuming ftp is an instance of Net::FTP)

Fred

WujcioL

8/1/2008 5:54:00 PM

0

Frederick Cheung wrote:
> On 1 Aug 2008, at 15:20, Mateusz Tybura wrote:
>
>>> Beyond firewalls, active ftp won't work behind a NAT device.
>>> Ftp servers sometimes say illegal port command if you tell them that
>>> your address is a private ip address like 192.168.x (your address on
>>> the network behind the nat device)
>>>
>>> Fred
>>
>> It can be it cause i'm connecting from small LAN. Got any idea how to
>> make it works even that host is beheind nat device?
>
> You need to be using passive ftp. According to the docs you just need
> to say ftp.passive = true (assuming ftp is an instance of Net::FTP)
>
> Fred

With ftp.passive my first code works but version using open-uri was
smaller. So I'm asking about how to set passive mode using open-uri?
--
Posted via http://www.ruby-....