Guest User

Untitled

a guest
Jul 17th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. require 'net/ftp'
  2. require 'ftools'
  3.  
  4. class PdfToFtp < AbstractProcessor
  5.  
  6. class << self
  7. def invoke(args)
  8. hostname = args[:hostname] || arg_error
  9. username = args[:username] || arg_error
  10. password = args[:password] || arg_error
  11. localpath = args[:localpath] || arg_error
  12. remotepath = args[:remotepath] || arg_error
  13. verbose = args[:verbose] || false
  14. additional_params = args[:params] || false
  15. node_id = args[:node_id] || arg_error
  16. Net::FTP.new(hostname,username,password) do |ftp|
  17.  
  18. puts "new ftp"
  19. ftp.login
  20. puts "login"
  21. ftp.chdir(remotepath)
  22. puts "chdir"
  23. if args[:node_id]
  24. puts "node_id is defined"
  25. local_file = File.join(localpath,node_id,"print/book.pdf")
  26. remote_dir = File.join(remotepath,node_id)
  27. remote_file = File.join(remote_dir,"book.pdf")
  28. ftp.mkdir(remote_dir)
  29. puts "mkdir done"
  30. ftp.putbinaryfile(local_file,remote_file)
  31. puts "putbinaryfile done"
  32. else
  33. puts "no node_id"
  34. end
  35. end
  36. end
  37.  
  38. def about
  39. super + "Puts generated PDFs on FTP server."
  40. end
  41.  
  42. def usage
  43. super + "Must supply ftp details."
  44. end
  45. end
  46. end
Add Comment
Please, Sign In to add comment