Create a gist now

Instantly share code, notes, and snippets.

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