We don't actually upload more than one file using the same connection.
parent
c63b4e291e
commit
6feefbe592
18
up.rb
18
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue