From 6feefbe5922b945d567006c760b2a1df94b4ece4 Mon Sep 17 00:00:00 2001 From: "Robert \"ar\" Gerus" Date: Thu, 23 May 2013 08:25:47 +0200 Subject: [PATCH] We don't actually upload more than one file using the same connection. --- up.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/up.rb b/up.rb index 2484e20..f14dcb4 100755 --- a/up.rb +++ b/up.rb @@ -8,7 +8,7 @@ require 'open-uri' UPLOAD_BASE_PATH = "/home/arachnist/public_html/c/" LINK_BASE_PATH = "https://arachnist.is-a.cat/c/" HOST = "i.am-a.cat" -USER = "arachnist" +USERNAME = "arachnist" ARGV.each do |path| Process.fork { @@ -17,16 +17,14 @@ ARGV.each do |path| ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/) content = open(path).read md5 = Digest::MD5.hexdigest(content) - Net::SCP.start(HOST, USER) do |scp| - # basically a glorified syntax sugar for (ext.nil? ? "" : ext) - begin - scp.upload!(StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext) - # we probably tried to add nil to a string ("ext" could possibly be nil) - rescue TypeError - scp.upload!(StringIO.new(content), UPLOAD_BASE_PATH + md5) - end + # basically a glorified syntax sugar for (ext.nil? ? "" : ext) + begin + Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext) + # we probably tried to add nil to a string ("ext" could possibly be nil) + rescue TypeError + Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5) 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