Class: Net::SSH::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/saucerest-ruby/gateway.rb

Overview

Instance Method Summary collapse

Instance Method Details

#close_remote(port, host = "127.0.0.1") ⇒ Object

Cancels port-forwarding over an open port that was previously opened via #open_remote.



28
29
30
31
32
33
34
# File 'lib/saucerest-ruby/gateway.rb', line 28

def close_remote(port, host = "127.0.0.1")
  ensure_open!

  @session_mutex.synchronize do
    @session.forward.cancel_remote(port, host)
  end
end

#open_remote(port, host, remote_port, remote_host = "127.0.0.1") ⇒ Object

Opens a SSH tunnel from a port on a remote host to a given host and port on the local side (equivalent to openssh -R parameter)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/saucerest-ruby/gateway.rb', line 6

def open_remote(port, host, remote_port, remote_host = "127.0.0.1")
  ensure_open!

  @session_mutex.synchronize do
    @session.forward.remote(port, host, remote_port, remote_host)
  end

  if block_given?
    begin
      yield [remote_port, remote_host]
    ensure
      close_remote(remote_port, remote_host)
    end
  else
    return [remote_port, remote_host]
  end
rescue Errno::EADDRINUSE
  retry
end