lib/capistrano/gateway.rb in capistrano-1.2.0 vs lib/capistrano/gateway.rb in capistrano-1.3.0

- old
+ new

@@ -28,11 +28,10 @@ MAX_PORT = 65535 MIN_PORT = 1024 def initialize(server, config) #:nodoc: @config = config - @pending_forward_requests = {} @next_port = MAX_PORT @terminate_thread = false @port_guard = Mutex.new mutex = Mutex.new @@ -68,15 +67,18 @@ # host to the server, via the gateway, and then opens and returns a new # Net::SSH connection via that port. def connect_to(server) connection = nil @config.logger.trace "establishing connection to #{server} via gateway" - port = next_port + local_port = next_port thread = Thread.new do begin - @session.forward.local(port, server, 22) - connection = SSH.connect('127.0.0.1', @config, port) + user, server_stripped, port = SSH.parse_server(server) + @config.ssh_options[:username] = user if user + remote_port = port || 22 + @session.forward.local(local_port, server_stripped, remote_port) + connection = SSH.connect('127.0.0.1', @config, local_port) @config.logger.trace "connection to #{server} via gateway established" rescue Errno::EADDRINUSE port = next_port retry rescue Exception => e