Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Simple FTP uploader script
- # by Gigamo <gigamo@gmail.com>
- # License: GPL
- require 'net/ftp'
- # {{{ Settings
- _host = ""
- _user = ""
- _pass = ""
- # }}}
- # Run the program
- begin
- puts "\033[1;33mRuFTP\033[0m v\033[1;31m0.2\033[0m by Gigamo\n"
- # If no arguments are given, if the user needs help or if no files are
- # specified, don't run
- if ARGV[0] == "-h" or ARGV.length == 0 or ARGV[1..-1].empty?
- puts "\033[1;31mYou fail. <3\033[0m\nUsage: ruftp.rb <remote_directory[current for current]> [file] [file2] [file3] ..."
- # Good to go
- else
- # Print current ftp directory
- puts "\033[1;33mDirectory\033[0m to be used:\n\033[1;31m>\033[0m #{ARGV[0]}"
- # Print user-given files
- puts "\n\033[1;33mFiles\033[0m to upload:\n"
- _files_to_upload = ARGV[1..-1].join("\n")
- _files_to_upload.each_line do |lines|
- puts "\033[1;31m>\033[0m #{lines}"
- end
- # Set up the ftp connection
- ftp = Net::FTP.new(_host)
- ftp.login(user = _user, passwd = _pass)
- # Change to user-specified FTP directory
- unless ARGV[0] == "current"
- ftp.chdir(ARGV[0])
- end
- # Finally, upload the files
- ARGV[1..-1].each do |file|
- puts "\nUploading <\033[1;33m#{file}\033[0m>..."
- ftp.put(file, File.basename(file))
- puts "Done"
- end
- # And close the connection
- ftp.close
- end
- # {{{ Debug
- rescue Exception => exp
- $stderr.puts "\033[0;31mError: \033[0m#{exp.message}"
- $stdout.flush
- # }}}
- end
Add Comment
Please, Sign In to add comment