Class | Net::SSH::Service::Forward |
In: |
lib/net/ssh/service/forward.rb
|
Parent: | Object |
session | [R] | The underlying connection service instance that the port-forwarding services employ. |
Returns a list of all active locally forwarded ports. The returned value is an array of arrays, where each element is a two-element tuple consisting of the local port and bind address corresponding to the forwarding port.
Enables SSH agent forwarding on the given channel. The forwarded agent will remain active even after the channel closes—the channel is only used as the transport for enabling the forwarded connection. You should never need to call this directly—it is called automatically the first time a session channel is opened, when the connection was created with :forward_agent set to true:
Net::SSH.start("remote.host", "me", :forwrd_agent => true) do |ssh| ssh.open_channel do |ch| # agent will be automatically forwarded by this point end ssh.loop end
Terminates an active local forwarded port. If no such forwarded port exists, this will raise an exception. Otherwise, the forwarded connection is terminated.
ssh.forward.cancel_local(1234) ssh.forward.cancel_local(1234, "0.0.0.0")
Requests that a remote forwarded port be cancelled. The remote forwarded port on the remote host, bound to the given address on the remote host, will be terminated, but not immediately. This method returns immediately after queueing the request to be sent to the server. If for some reason the port cannot be cancelled, an exception will be raised (asynchronously).
If you want to know when the connection has been cancelled, it will no longer be present in the active_remotes list. If you want to block until the port is no longer active, you could do something like this:
ssh.forward.cancel_remote(1234, "0.0.0.0") ssh.loop { ssh.forward.active_remotes.include?([1234, "0.0.0.0"]) }
Starts listening for connections on the local host, and forwards them to the specified remote host/port via the SSH connection. This method accepts either three or four arguments. When four arguments are given, they are:
If three arguments are given, it is as if the local bind address is "127.0.0.1", and the rest are applied as above.
ssh.forward.local(1234, "www.capify.org", 80) ssh.forward.local("0.0.0.0", 1234, "www.capify.org", 80)
Requests that all connections on the given remote-port be forwarded via the local host to the given port/host. The last argument describes the bind address on the remote host, and defaults to 127.0.0.1.
This method will return immediately, but the port will not actually be forwarded immediately. If the remote server is not able to begin the listener for this request, an exception will be raised asynchronously.
If you want to know when the connection is active, it will show up in the active_remotes list. If you want to block until the port is active, you could do something like this:
ssh.forward.remote(80, "www.google.com", 1234, "0.0.0.0") ssh.loop { !ssh.forward.active_remotes.include?([1234, "0.0.0.0"]) }