Guest User

Untitled

a guest
Oct 3rd, 2018
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. require 'net/ftp'
  2. require 'rubygems'
  3. require 'highline/import'
  4.  
  5. hostname = ask('Enter the hostname of the remote computer: ')
  6. uname = ask('Enter the username for the remote computer: ')
  7. pass = ask('Enter the password associated with the username: '){|p| p.echo = "*" }
  8.  
  9. $ftp = Net::FTP.new
  10. $ftp.passive = true
  11. puts "\nConnecting to "+hostname+"..."
  12. $ftp.connect hostname
  13. $ftp.login uname, pass
  14.  
  15. choice = ask('Do you want to send or retrieve a file? (S/R)')
  16.  
  17. def sendfile
  18. filename = ask('Enter the full path of the file you wish to send: ')
  19. rfilename = ask('Enter the directory and filename where this file should be placed: ')
  20. puts "Sending file..."
  21. $ftp.puttextfile filename, rfilename
  22. puts "File successfully sent."
  23. end
  24.  
  25. def getfile
  26. filename = ask('Enter the path of the file you wish to retrieve: ')
  27. puts 'Downloading file...'
  28. $ftp.gettextfile filename
  29. puts 'File successfully downloaded.'
  30. end
  31.  
  32. if choice.downcase == 's'
  33. sendfile
  34. else
  35. getfile
  36. end
  37.  
  38. $ftp.close
Add Comment
Please, Sign In to add comment