Net-ssh: Trouble forwarding local ports to a remote server

Here's the plan: I need to forward a Samba connection on my machine to a
remote server. When logging into the remote server, I should be able to
run smbclient -L \\localhost and see the Samba server from my machine.
Here's the script I'm running:

require 'net/ssh'

Net::SSH.start(hostname, user, :password => pass) do |sshConnection|
  sshConnection.forward.remote(445, 'localhost', 445)

  sshConnection.loop do
    sleep 0.5
    ! sshConnection.forward.active_remotes.include?([445, '127.0.0.1'])
  end

  puts 'Connection open'
  sleep 60
end

A chunk of this is just in there for testing, but within that 60-second
window, I should be able to log in to the remote server and run that
smbclient -L \\localhost command and see my shares, right?

Currently, it's not working. Here's what I've found:
- ssh -R 445:localhost:445 user@hostname forwards fine and I can see the
shares (expected)
- If the script isn't running and I run smbclient, I get an error about
the server not running (expected)
- If the script is running and I run smbclient, it hangs until the 60
seconds are up (unexpected)

Any thoughts?

···

--
Posted via http://www.ruby-forum.com/.

This is interesting, if I slide sshConnection.loop { true } into this
script, it works. Why is this?

···

--
Posted via http://www.ruby-forum.com/.

Net::SSH::Connection::Session#loop appears to actually start the SSH event loop, which handles processing the IO (in this case, forwarding the connections).

The third paragraph here hints at this: http://net-ssh.github.com/net-ssh/classes/Net/SSH.html

-Justin

···

On 05/14/2012 11:37 AM, Maxwell Pray wrote:

This is interesting, if I slide sshConnection.loop { true } into this
script, it works. Why is this?