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/
slackware-12.0/CHECKSUMS.md5.asc")
get.get
···
--
My own blog (in polish) :
wujciol.yoyo.pl
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
···
On Wed, Jul 30, 2008 at 1:30 PM, Mateusz Tybura <wujciol@gmail.com> wrote:
puts open("ftp://anonymous:anon@sunsite.icm.edu.pl/pub/Linux/slackware/slackware-12.0/CHECKSUMS.md5.asc").read
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.
Maybe because active ftp and your firewall, try:
require 'open-uri'
open("ftp://whatever.ftp.site", :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.
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]
···
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.
--
Killer Ruby PDF Generation named after a magnificent sea creature:
GitHub - practicingruby/prawn: THIS REPOSITORY HAS MOVED TO: | Non-tech stuff at:
http://metametta.blogspot.com
Martin Boese wrote:
Maybe because active ftp and your firewall, try:
require 'open-uri'
open("ftp://whatever.ftp.site", :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-forum.com/\.
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
···
On 1 Aug 2008, at 14:46, Gregory Brown wrote:
On Thu, Jul 31, 2008 at 3:29 AM, WujcioL <WujcioL@gmail.com> wrote:
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:
GitHub - practicingruby/prawn: THIS REPOSITORY HAS MOVED TO: | Non-tech stuff at:
http://metametta.blogspot.com
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
···
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?