[Help] My simple downloader doesn't work

W

WujcioL

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:

equire '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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top