Created
September 26, 2011 13:53
-
-
Save uu59/1242278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- coding: utf-8 | |
=begin | |
Mac or Linux with imagemagick | |
=end | |
HOST = "114.160.71.150" | |
DIR_NAME = "gyazzo" | |
require "net/ftp" | |
imagefile = ARGV[0] | |
if imagefile && File.exist?(imagefile) | |
tmpfile = "/tmp/image_upload#{$$}#{File.extname(imagefile)}" | |
system "convert", imagefile, tmpfile | |
else | |
tmpfile = "/tmp/image_upload#{$$}.png" | |
capture_cmd = case RUBY_PLATFORM | |
when /darwin/ | |
"screencapture -i #{tmpfile}" | |
else | |
"import #{tmpfile}" | |
end | |
system capture_cmd | |
end | |
begin | |
ftp = Net::FTP.new | |
ftp.connect(HOST) | |
ftp.login("anonymous", "mail@to") | |
ftp.binary = true | |
ftp.chdir(DIR_NAME) | |
unless ftp.pwd.match /#{DIR_NAME}/ | |
ftp.mkdir(DIR_NAME) | |
ftp.chdir(DIR_NAME) | |
end | |
begin | |
upfile = "#{Time.now.to_f}#{File.extname(tmpfile)}" | |
end while ftp.nlst(upfile) != [] | |
ftp.put(tmpfile, upfile) | |
ftp.quit | |
puts "ftp://#{HOST}/gyazzo/#{upfile}" | |
rescue => ex | |
puts ex | |
puts ex.backtrace | |
puts "something error occurred" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment