Skip to content

Instantly share code, notes, and snippets.

@grekko
Created January 15, 2011 19:18
Show Gist options
  • Save grekko/781167 to your computer and use it in GitHub Desktop.
Save grekko/781167 to your computer and use it in GitHub Desktop.
Retrieve all CCC 27C3 Recordings via FTP from one of for random FTP Mirrors
require 'net/ftp'
require 'uri'
ftp_hosts_hq = %w(
ftp://ftp.halifax.rwth-aachen.de/CCC/27C3/mp4-h264-HQ/
ftp://mirror.fem-net.de/CCC/27C3/mp4-h264-HQ/
ftp://ftp.selfnet.de/CCC/27C3/mp4-h264-HQ/
ftp://ftp.uni-kl.de/CCC/27C3/mp4-h264-HQ/
)
file_match_regexp = /.*\.mp4$/
uri = URI.parse ftp_hosts_hq[rand(ftp_hosts_hq.length)]
puts "using ftp-host: " + uri.host
Net::FTP.open(uri.host) do |ftp|
ftp.login
files = ftp.chdir(uri.path)
files = ftp.nlst
files.each do |file|
if File.exist? file then
puts "skipping " + file + ", since it already exists"
next
end
if !file.match(file_match_regexp) then
puts "skipping " + file + ", since it doesnt match " + file_match_regexp.to_s
next
end
filesize = ftp.size(file)
transferred = 0
puts "downloading: " + file + ", Size: " + filesize.to_s + " Bytes"
ftp.getbinaryfile(file, file, 1024) if file.match(/.*\.mp4$/) do
transferred += data.size
percent_finished = ((transferred).to_f/filesize.to_f)*100
p "#{percent_finished.round}% complete"
end
end
ftp.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment