Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'directory_watcher' # gem install directory_watcher
- require 'net/sftp' # gem install net-sftp
- SEARCH_DIR = File.expand_path('~/Downloads')
- SERVER = ''
- USERNAME = ''
- PASSWORD = ''
- REMOTE_DIR = ''
- def upload(path)
- Net::SFTP.start(SERVER, USERNAME, :password => PASSWORD) do |sftp|
- sftp.upload(path, File.join(REMOTE_DIR, File.basename(path)))
- end
- end
- def remove(path)
- File.delete(path)
- end
- def handle_torrent(path)
- puts "Uploading file: #{path}"
- upload(path)
- remove(path)
- end
- watcher = DirectoryWatcher.new(SEARCH_DIR)
- watcher.glob = '*.torrent'
- watcher.add_observer do |*args|
- args.each do |event|
- handle_torrent(event.path) if event.type == :added
- end
- end
- watcher.start
- gets
Add Comment
Please, Sign In to add comment