Guest User

Untitled

a guest
Jun 3rd, 2018
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # Simple FTP uploader script
  3. # by Gigamo <gigamo@gmail.com>
  4. # License: GPL
  5. require 'net/ftp'
  6. # {{{ Settings
  7. _host = ""
  8. _user = ""
  9. _pass = ""
  10. # }}}
  11. # Run the program
  12. begin
  13. puts "\033[1;33mRuFTP\033[0m v\033[1;31m0.2\033[0m by Gigamo\n"
  14. # If no arguments are given, if the user needs help or if no files are
  15. # specified, don't run
  16. if ARGV[0] == "-h" or ARGV.length == 0 or ARGV[1..-1].empty?
  17. puts "\033[1;31mYou fail. <3\033[0m\nUsage: ruftp.rb <remote_directory[current for current]> [file] [file2] [file3] ..."
  18. # Good to go
  19. else
  20. # Print current ftp directory
  21. puts "\033[1;33mDirectory\033[0m to be used:\n\033[1;31m>\033[0m #{ARGV[0]}"
  22.  
  23. # Print user-given files
  24. puts "\n\033[1;33mFiles\033[0m to upload:\n"
  25. _files_to_upload = ARGV[1..-1].join("\n")
  26. _files_to_upload.each_line do |lines|
  27. puts "\033[1;31m>\033[0m #{lines}"
  28. end
  29.  
  30. # Set up the ftp connection
  31. ftp = Net::FTP.new(_host)
  32. ftp.login(user = _user, passwd = _pass)
  33. # Change to user-specified FTP directory
  34. unless ARGV[0] == "current"
  35. ftp.chdir(ARGV[0])
  36. end
  37.  
  38. # Finally, upload the files
  39. ARGV[1..-1].each do |file|
  40. puts "\nUploading <\033[1;33m#{file}\033[0m>..."
  41. ftp.put(file, File.basename(file))
  42. puts "Done"
  43. end
  44.  
  45. # And close the connection
  46. ftp.close
  47. end
  48. # {{{ Debug
  49. rescue Exception => exp
  50. $stderr.puts "\033[0;31mError: \033[0m#{exp.message}"
  51. $stdout.flush
  52. # }}}
  53. end
Add Comment
Please, Sign In to add comment