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/"
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue