##### # Name: drweb updates downloader # Version: 0.2 # by Lambda Core Facility # 2007, GPL v.3 ##### require 'net/http' require 'net/ftp' require 'uri' ##### User config #Download directory DIRECTORY = 'down' #Dr.Web directory DRWEB = 'd:/Program Files/DrWeb' #Unpacker UZIP = 'unzip.exe' ##### Program SERVER = 'download.drweb.com' PAGE = "bases/" def parse(data, what) res = Array.new data.scan(what) { |x| res << x} return(res) end def read_page(page) h = Net::HTTP.new(SERVER, 80) resp, data = h.get("/#{page}", nil) if resp.message != "OK" puts "Error!" Kernel.exit end return(data) end def get_file(host, dir, file) Net::FTP.open(host) do |ftp| ftp.login("ftp", "drweb@update.com") ftp.chdir(dir) list = ftp.nlst #Always download today updates if list.include?(file) && (!File.exist?(DIRECTORY+'/'+file) || \ file =~ /today/) ftp.getbinaryfile(file, DIRECTORY+'/'+file, 512) puts " ...downloading" else puts " ...skipping" end ftp.close end end def unpack(file) system("#{UZIP} -o #{DIRECTORY.gsub(/\//, "\\")}\\#{file}.zip -d \"#{DRWEB.gsub(/\//, "\\")}\"") end def install_updates Dir.foreach(DIRECTORY) do |x| if x =~ /(drw.*)\.zip/ name = $1 if !File.exist?(DRWEB+'/'+name+'.vdb') unpack(name) end end end #Unpack today files Dir.foreach(DIRECTORY) do |x| unpack($1) if x =~ /(d..today.*)\.zip/ end end ##### MAIN z = Array.new r = String.new r = read_page(PAGE) z = parse(r, %r{ftp:.*?zip}i) z.each do | url | addr = URI.parse(url) host = addr.host file = File.basename(addr.path) dir = File.dirname(addr.path) print file get_file(host, dir, file) end install_updates ##### END