Skip to content

Instantly share code, notes, and snippets.

@uu59
Created September 26, 2011 13:53
Show Gist options
  • Save uu59/1242278 to your computer and use it in GitHub Desktop.
Save uu59/1242278 to your computer and use it in GitHub Desktop.
# -- 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