Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Open 2 Folder Paths in Ruby Program without any Errors Showing

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 546
    Answer it
    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: