Class: SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_smart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, login, password, inbox, work, outbox) ⇒ SSH

Returns a new instance of SSH.



10
11
12
13
14
15
16
17
# File 'lib/ssh_smart.rb', line 10

def initialize(host, , password, inbox, work, outbox)
  @host = host
  @login = 
  @password = password
  @inbox = inbox
  @work = work
  @outbox = outbox
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/ssh_smart.rb', line 8

def host
  @host
end

#inboxObject

Returns the value of attribute inbox.



8
9
10
# File 'lib/ssh_smart.rb', line 8

def inbox
  @inbox
end

#loginObject

Returns the value of attribute login.



8
9
10
# File 'lib/ssh_smart.rb', line 8

def 
  @login
end

#outboxObject

Returns the value of attribute outbox.



8
9
10
# File 'lib/ssh_smart.rb', line 8

def outbox
  @outbox
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/ssh_smart.rb', line 8

def password
  @password
end

#workObject

Returns the value of attribute work.



8
9
10
# File 'lib/ssh_smart.rb', line 8

def work
  @work
end

Instance Method Details

#checkFolderFile(dirFile, fileName) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/ssh_smart.rb', line 28

def checkFolderFile(dirFile, fileName)
  returnMethod = false
  result = ''
  method = false
  Net::SSH.start(@host, @login, password: @password) do |ssh|
    result = ssh.exec!("cd #{dirFile} && ls")
  end
  method = true if result.include? fileName
  method
end

#copyFileToRemote(fileRemote) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/ssh_smart.rb', line 19

def copyFileToRemote(fileRemote)
  method = false
  Net::SCP.start(@host, @login, password: @password) do |scp|
    scp.upload(fileRemote, @inbox)
  end
  method = true if checkFolderFile(@outbox, File.basename(fileRemote))
  method
end

#retornarObject



39
40
41
# File 'lib/ssh_smart.rb', line 39

def retornar
  puts 'Funcionando!!'
end