Guest User

Untitled

a guest
Mar 10th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'net/ftptls'
  4. require 'optparse'
  5. require 'irb'
  6. require 'irb/workspace'
  7.  
  8. module IRB
  9. def IRB.session(name, object)
  10. IRB.setup(name)
  11. irb = Irb.new(IRB::WorkSpace.new(object))
  12. @CONF[:MAIN_CONTEXT] = irb.context
  13.  
  14. trap("SIGINT") do
  15. irb.signal_handle
  16. end
  17. catch(:IRB_EXIT) do
  18. irb.eval_input
  19. end
  20. end
  21. end
  22.  
  23. class SecureFTP
  24. def initialize(host, port = 21, user = nil, pass = nil)
  25. @session = Net::FTPTLS.new
  26. @session.passive = true
  27. @session.connect(host, port)
  28. @session.login(user, pass) if user && pass
  29. end
  30. def close
  31. @session.close
  32. end
  33. def method_missing(meth, *args, &block)
  34. if @session.respond_to?(meth)
  35. @session.send(meth, *args, &block)
  36. else
  37. @session.sendcmd(site_cmd(meth, *args))
  38. end
  39. end
  40. def site_cmd(meth, *args)
  41. cmd = "site #{meth}"
  42. cmd << " #{args.join(' ')}" unless args.empty?
  43. cmd
  44. end
  45. end
  46.  
  47. options = { :port => 21 }
  48. OptionParser.new do |opt|
  49. opt.banner = "Usage: $0 [hostname] [options]"
  50. opt.on('-u', '--user', String, 'FTP Username') { |v| options[:user] = v }
  51. opt.on('-p', '--pass', String, 'FTP Password') { |v| options[:pass] = v }
  52. opt.on('-P', '--port', Integer, 'FTP Port') { |v| options[:port] = v }
  53. opt.parse!(ARGV)
  54. end
  55.  
  56. begin
  57. ftp = SecureFTP.new(ARGV[0], options[:port], options[:username], options[:password])
  58. IRB.session(ftp.class.name, ftp)
  59. ensure
  60. ftp.close
  61. end
Add Comment
Please, Sign In to add comment