Guest User

Untitled

a guest
Aug 5th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. require 'rubygems'
  2. require 'directory_watcher' # gem install directory_watcher
  3. require 'net/sftp' # gem install net-sftp
  4.  
  5. SEARCH_DIR = File.expand_path('~/Downloads')
  6. SERVER = ''
  7. USERNAME = ''
  8. PASSWORD = ''
  9. REMOTE_DIR = ''
  10.  
  11. def upload(path)
  12. Net::SFTP.start(SERVER, USERNAME, :password => PASSWORD) do |sftp|
  13. sftp.upload(path, File.join(REMOTE_DIR, File.basename(path)))
  14. end
  15. end
  16.  
  17. def remove(path)
  18. File.delete(path)
  19. end
  20.  
  21. def handle_torrent(path)
  22. puts "Uploading file: #{path}"
  23. upload(path)
  24. remove(path)
  25. end
  26.  
  27. watcher = DirectoryWatcher.new(SEARCH_DIR)
  28. watcher.glob = '*.torrent'
  29. watcher.add_observer do |*args|
  30. args.each do |event|
  31. handle_torrent(event.path) if event.type == :added
  32. end
  33. end
  34.  
  35. watcher.start
  36. gets
Add Comment
Please, Sign In to add comment