Method: Net::SSH::Service::Forward#cancel_remote
- Defined in:
- lib/net/ssh/service/forward.rb
#cancel_remote(port, host = "127.0.0.1") ⇒ Object
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"]) }
251 252 253 254 255 256 257 258 259 |
# File 'lib/net/ssh/service/forward.rb', line 251 def cancel_remote(port, host = "127.0.0.1") session.send_global_request("cancel-tcpip-forward", :string, host, :long, port) do |success, response| if success @remote_forwarded_ports.delete([port, host]) else raise Net::SSH::Exception, "could not cancel remote forward request on #{host}:#{port}" end end end |