Skip to content

Instantly share code, notes, and snippets.

@DNNX
Created August 9, 2011 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DNNX/1134155 to your computer and use it in GitHub Desktop.
Save DNNX/1134155 to your computer and use it in GitHub Desktop.
require 'net/ftp'
require 'timeout'
ftp = Net::FTP.new('ftp.sra.ebi.ac.uk')
ftp.login
puts "connected!"
errors = []
samples = ["SRR016000"]
samples.each do |sample|
files = ftp.chdir("vol1/fastq/SRR016/#{sample}/")
puts "changed directory"
#files = ftp.list('SRR*')
begin
bytes_downloaded = 0
file_name = "#{sample}_1.fastq.gz"
Timeout.timeout(20000) do
file_size = ftp.size(file_name)
ftp.getbinaryfile(file_name) do |chunk|
bytes_downloaded += chunk.size
puts "#{bytes_downloaded} of #{file_size} bytes downloaded (#{bytes_downloaded * 100 / file_size}%)."
end
end
rescue Timeout::Error
errors << "File download timed out for: #{sample}"
puts errors.last
end
end
ftp.close
puts "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment