Method: FileCopy.ssh_connect
- Defined in:
- lib/file_copy/copy.rb
.ssh_connect(username, password, server) ⇒ Object
Creates ssh connection, assumes username and password or without password but with ssh keys.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/file_copy/copy.rb', line 11 def ssh_connect(username, password, server) username = (username and username.length > 0) ? username : ENV['USER'] password = (password and password.length > 0) ? password : nil port = 22 # 22 is a standart SSH port raise "Undefined server" unless server Log.debug1("Trying to connect(ssh): %s, %s, %s, %s.", username, password, server, port) if (username and password) Net::SSH.start(server, username, :password => password, :port => port) elsif (username) Net::SSH.start(server, username, :port => port) else raise("Undefined username") end end |