Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After using ssh.sftp, ssh channel/exec hangs. #13

Open
ryanstout opened this issue May 30, 2012 · 1 comment
Open

After using ssh.sftp, ssh channel/exec hangs. #13

ryanstout opened this issue May 30, 2012 · 1 comment

Comments

@ryanstout
Copy link

I've attached some sample code. I'm trying to get the exit status of commands, and also use the same connection to upload a file. You can see in the example that the command runs fine until I've used .sftp from the ssh connection. Also, if I do this after the sftp call it works:

connection.sftp.close_channel()
connection.instance_variable_set('@sftp', nil)

I'm thinking there's a way to keep both channels open (for the sftp and the command) and still have it work.

Thanks for the great library. Let me know if I can help track this one down.

require 'net/ssh'
require 'net/sftp'


class TestSSH
  def run_command(connection, command)
    exit_code = nil

    connection.open_channel do |channel|
      channel.exec(command) do |ch, success|
        unless success
          abort "FAILED: couldn't execute command (connection.channel.exec)"
        end

        channel.on_request("exit-status") do |ch,data|
          exit_code = data.read_long
        end
      end
    end
    puts "Loop on connection"
    connection.loop
    puts "Finished Loop"

    return exit_code
  end

  def test
    connection = Net::SSH.start('44dates.com', 'ubuntu')

    puts "Run ls"
    run_command(connection, "ls")

    puts "Upload File"
    io = StringIO.new("some text")
    connection.sftp.upload!(io, "somefile.txt")

    puts "Run ls Again"
    run_command(connection, "ls")
    puts "Finished Running ls again"

    connection.close
  end
end

TestSSH.new.test
@delano
Copy link
Collaborator

delano commented Sep 19, 2012

Thanks for the report. The project is in maintenance mode but I'm happy to pull in a patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants