Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'net/ftptls'
- require 'optparse'
- require 'irb'
- require 'irb/workspace'
- module IRB
- def IRB.session(name, object)
- IRB.setup(name)
- irb = Irb.new(IRB::WorkSpace.new(object))
- @CONF[:MAIN_CONTEXT] = irb.context
- trap("SIGINT") do
- irb.signal_handle
- end
- catch(:IRB_EXIT) do
- irb.eval_input
- end
- end
- end
- class SecureFTP
- def initialize(host, port = 21, user = nil, pass = nil)
- @session = Net::FTPTLS.new
- @session.passive = true
- @session.connect(host, port)
- @session.login(user, pass) if user && pass
- end
- def close
- @session.close
- end
- def method_missing(meth, *args, &block)
- if @session.respond_to?(meth)
- @session.send(meth, *args, &block)
- else
- @session.sendcmd(site_cmd(meth, *args))
- end
- end
- def site_cmd(meth, *args)
- cmd = "site #{meth}"
- cmd << " #{args.join(' ')}" unless args.empty?
- cmd
- end
- end
- options = { :port => 21 }
- OptionParser.new do |opt|
- opt.banner = "Usage: $0 [hostname] [options]"
- opt.on('-u', '--user', String, 'FTP Username') { |v| options[:user] = v }
- opt.on('-p', '--pass', String, 'FTP Password') { |v| options[:pass] = v }
- opt.on('-P', '--port', Integer, 'FTP Port') { |v| options[:port] = v }
- opt.parse!(ARGV)
- end
- begin
- ftp = SecureFTP.new(ARGV[0], options[:port], options[:username], options[:password])
- IRB.session(ftp.class.name, ftp)
- ensure
- ftp.close
- end
Add Comment
Please, Sign In to add comment