We don't actually upload more than one file using the same connection.

master
Robert "ar" Gerus 2013-05-23 08:25:47 +02:00
parent c63b4e291e
commit 6feefbe592
1 changed files with 8 additions and 10 deletions

18
up.rb
View File

@ -8,7 +8,7 @@ require 'open-uri'
UPLOAD_BASE_PATH = "/home/arachnist/public_html/c/" UPLOAD_BASE_PATH = "/home/arachnist/public_html/c/"
LINK_BASE_PATH = "https://arachnist.is-a.cat/c/" LINK_BASE_PATH = "https://arachnist.is-a.cat/c/"
HOST = "i.am-a.cat" HOST = "i.am-a.cat"
USER = "arachnist" USERNAME = "arachnist"
ARGV.each do |path| ARGV.each do |path|
Process.fork { Process.fork {
@ -17,16 +17,14 @@ ARGV.each do |path|
ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/) ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/)
content = open(path).read content = open(path).read
md5 = Digest::MD5.hexdigest(content) md5 = Digest::MD5.hexdigest(content)
Net::SCP.start(HOST, USER) do |scp| # basically a glorified syntax sugar for (ext.nil? ? "" : ext)
# basically a glorified syntax sugar for (ext.nil? ? "" : ext) begin
begin Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext)
scp.upload!(StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext) # we probably tried to add nil to a string ("ext" could possibly be nil)
# we probably tried to add nil to a string ("ext" could possibly be nil) rescue TypeError
rescue TypeError Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5)
scp.upload!(StringIO.new(content), UPLOAD_BASE_PATH + md5)
end
end end
printf("%s\n\t=> %s%s%s\n", path, LINK_BASE_PATH, md5, ext) printf("%s\t=> %s%s%s\n", path, LINK_BASE_PATH, md5, ext)
} }
end end