#! /usr/bin/env ruby | |
require 'rubygems' | |
require 'net/ssh' | |
require "net/ssh/gateway" | |
# Terminal equivalent | |
# #ssh -R0.0.0.0:9999:localhost:3000 sid@abc.idyllic-software.com | |
puts "Enter the remote server name you wish to forward your local port to: (staging.example.com)" | |
remote_host = gets.chomp | |
puts "Enter the remote port you wish your local app to be available on - on the remote server (ex: 9999)" | |
remote_port = gets.chomp | |
puts "Enter remote server user to ssh with" | |
remote_user = gets.chomp | |
puts "Enter local port to forward" | |
local_port = gets.chomp | |
remote_host = "abc.idyllic-software.com" if remote_host.empty? || remote_host.nil? | |
remote_port = 9999 if remote_port.empty? || remote_port.nil? | |
remote_user = "sid" if remote_user.empty? || remote_user.nil? | |
local_port = 3000 if local_port.empty? || local_port.nil? | |
gateway = Net::SSH::Gateway.new(remote_host, remote_user) | |
puts "Forwarding 127.0.0.1:#{local_port} to #{remote_host}:#{remote_port}" | |
#remote_host = "abc.idyllic-software.com" | |
Net::SSH.start(remote_host, remote_user) do |ssh| | |
puts "Connecting..." | |
#puts ssh.inspect | |
ssh.logger.sev_threshold = Logger::Severity::DEBUG | |
#remote forward from remote 127.0.0.1:3000 to 0.0.0.0:9999 established | |
ssh.forward.remote(local_port, '127.0.0.1', remote_port, remote_host) | |
ssh.loop { true } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment