Created
May 27, 2010 04:27
-
-
Save reaktivo/415460 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
#!/usr/bin/env ruby | |
require 'json' | |
require 'typhoeus' | |
require 'ap' | |
require 'digest/sha1' | |
require 'highline/import' | |
require 'optparse' | |
require 'net/ssh' | |
require 'net/sftp' | |
class Zootool | |
API_KEY = "5f0d660651d4c9e69ce0bc9ae772c8e9" | |
API_URL = 'http://zootool.com/api' | |
def initialize | |
puts "Zootool Remote Copying Tool" | |
username = ask("What is your Zootool username?") | |
password = ask("What is your password") {|q| q.echo = "*"} | |
#username = "XXXXXXX" | |
#password = "XXXXXXX" | |
host_password = ask("What is your host password") {|q| q.echo = "*"} | |
#host_password = "XXX" | |
# target = ask("What is the remote host target file?") | |
user = "reaktivo" | |
host = "reaktivo.com" | |
root = "/home/reaktivo/reaktivo.com" | |
temp_folder = "zoofiles" | |
folder = "#{root}/#{temp_folder}" | |
target = "#{user}@#{host}:#{folder}" | |
# public_url = ask("What is the url for accesing this file?") | |
public_target = "http://reaktivo.com/zoofiles" | |
auth = { | |
:username => username.downcase, | |
:password => Digest::SHA1.hexdigest(password), | |
:method => Typhoeus::Easy::AUTH_TYPES[:CURLAUTH_DIGEST] | |
} | |
Net::SFTP.start(host, user, :password => host_password) do |sftp| | |
sftp.mkdir!(folder) | |
directory = Dir.new(Dir.pwd) | |
Dir.foreach(Dir.pwd) do |f| | |
if File.file?(f) | |
puts "Copying #{f} to remote host" | |
sftp.upload!(f, "#{folder}/#{f}") | |
puts "Adding #{f} to Zoo\n" | |
e = Typhoeus::Easy.new | |
e.auth = auth | |
e.url = "#{API_URL}/add" | |
e.params = { | |
:apikey => API_KEY, | |
:url => "#{public_target}/#{f}", | |
:title => f, | |
} | |
e.perform | |
# ap JSON.parse e.response_body | |
puts "Finished adding #{f} to Zoo\n\n\n" | |
sftp.remove!("#{folder}/#{f}") | |
end #if | |
end #Dir foreach | |
puts "Upload complete" | |
sftp.rmdir!(folder) | |
end #Net::SFTP.start | |
end #initialize | |
end | |
zoo = Zootool.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment