class Net::SSH::Service::Forward
def remote(port, host, remote_port, remote_host = "127.0.0.1")
end
raise Net::SSH::Exception, "remote forwarding request failed"
if got_remote_port == :error
session.loop { !got_remote_port }
end
:no_exception # will yield the exception on my own thread
got_remote_port = actual_remote_port || :error
remote(port, host, remote_port, remote_host) do |actual_remote_port|
got_remote_port = nil
like this:
If you want to block until the port is active, you could do something
returns :no_exception, the "failed binding" exception will not be thrown.
that was actually bound to, or nil if the binding failed. If the block
request receives a response. This block will be passed the remote_port
You may pass a block that will be called when the the port forward
interfaces for IPv4 and IPv6, respectively.
- "127.0.0.1" and "::1" indicate listening on the loopback
[RFC3513]).
the SSH implementation on loopback addresses only ([RFC3330] and
- "localhost" means to listen on all protocol families supported by
- "::" means to listen on all IPv6 addresses.
- "0.0.0.0" means to listen on all IPv4 addresses.
families supported by the SSH implementation.
- "" means that connections are to be accepted on all protocol
special values:
remote_host is interpreted by the server per RFC 4254, which has these
list.
the port number. The assigned port will show up in the # #active_remotes
To request an ephemeral port on the remote server, provide 0 (zero) for
listener for this request, an exception will be raised asynchronously.
forwarded immediately. If the remote server is not able to begin the
This method will return immediately, but the port will not actually be
bind address on the remote host, and defaults to 127.0.0.1.
the local host to the given port/host. The last argument describes the
Requests that all connections on the given remote-port be forwarded via
def remote(port, host, remote_port, remote_host = "127.0.0.1") session.send_global_request("tcpip-forward", :string, remote_host, :long, remote_port) do |success, response| if success remote_port = response.read_long if remote_port == 0 debug { "remote forward from remote #{remote_host}:#{remote_port} to #{host}:#{port} established" } @remote_forwarded_ports[[remote_port, remote_host]] = Remote.new(host, port) yield remote_port, remote_host if block_given? else instruction = if block_given? yield :error end unless instruction == :no_exception error { "remote forwarding request failed" } raise Net::SSH::Exception, "remote forwarding request failed" end end end end