Skip to content

Instantly share code, notes, and snippets.

@venj
Last active August 29, 2015 14:03
Show Gist options
  • Save venj/7060ebefb3679967a3b0 to your computer and use it in GitHub Desktop.
Save venj/7060ebefb3679967a3b0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Will download to Files in current directory.
# To download:
# ruby down.rb
require "open-uri"
require "fileutils"
include FileUtils
USER = "data_public"
PWD = "GDdci"
BASE_URL = "http://data.cgiar-csi.org/srtm/tiles/ASCII/"
print "Parsing directory..."
lines = open(BASE_URL, :http_basic_authentication => [USER, PWD]).readlines
puts "done."
puts
regex = />([^<>]+?\.zip)</
target = "Files"
mkdir target unless File.exists? target
lines.each do |l|
matches = regex.match(l)
next if matches.nil?
cd target do
file = matches[1]
print "Downloading #{file}..."
open(file, "wb") { |f| f.write open(BASE_URL + regex.match(l)[1], :http_basic_authentication => [USER, PWD]).read }
puts "done."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment