require "net/ssh"
require 'net/ssh/shell'
require 'capistrano/rails'
require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL
@hostname = "lwa1001.env-10-100-222.iagcloud"
@username = "admin"
@password = "password1"
@cmd = "ls -la"
res = ""
ssh = Net::SSH.start(@hostname, @username, :password => @password) do |ssh|
ssh.shell do |sh|
path="/cguclaim/virtual/data/logs/gwlogs/ClaimCenter/"
path="/claims_virt/inout/"
require 'pry'; binding.pry;
res = ssh.exec! (@cmd) do |channel, stream, data|
Dir.chdir('/destination_directory')
Dir.glob('*').select {|f| File.directory? f}
end
puts res
rescue
puts "Unable to connect to #{@hostname} using #{@username}/#{@password}"
end
# res = ssh.exec!(@cmd)
# if Dir.exist?(path) && File.directory?(path)
# puts "Directory exists"
# else
# puts "Directory not found"
# end
The code shown below currently comes up as only "Directory not found" but I want to find the two directories without any problems using Capistrano/Rails so it can be from a remote server to a local host. I am not sure if this code will work to find out the folders from remote to local path?
if Dir.exist?(path) && File.directory?(path)
puts "Directory exists"
else
puts "Directory not found" end
0 Answer(s)