Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:09:58+00:00 2026-06-07T02:09:58+00:00

I have the following Port Forwarding created with Net::SSH : def connectToCustomerSystem Net::SSH.start(localhost, ‘myuser’,

  • 0

I have the following Port Forwarding created with Net::SSH:

def connectToCustomerSystem
  Net::SSH.start("localhost", 'myuser', :password => "password") do |ssh|
    logger.debug ssh.exec!("hostname")
    ssh.forward.local(1234, "www.capify.org", 80) 
    #ssh.loop { true } #dont use loop to directly render director/index
  end  
  render :controller => "director", :action => "index"
end 

Now i will cancel this Connection via “ssh.forward.cancel_local(1234)” in a new, other method.

def disconnectForwarding
  ssh.forward.cancel_local(1234)
end

But, of course, “ssh” isnt valid in this context. How could i search all available Objects with Type “Net::SSH”? Or are there any other ways how i could quit a specific Forwarding (because in the end, there will be much Forwards for some different Users, and i dont want to kill all, just a specific one).

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:10:00+00:00Added an answer on June 7, 2026 at 2:10 am

    I see you’re trying to keep stateful Ruby objects around while interacting with Rails. This doesn’t play well with the Rails “shared nothing” approach to servers. Not only will ssh not be in scope because of the block being out of scope for your method, you will be talking to a different worker process next time.

    What you need is separate longer running ruby processes in the background to manage the ssh connection. A simple way to do this is launch a ruby script and connect to the object managing ssh using DRb. You can then reconnect to the Ruby process managing the connection each time a request is handled and give it commands over DRb. The ssh variable might work as an instance variable inside the object you speak with over DRb in this case (it looks like you can set this to loop so it sticks around).

    There are some terrible approaches to getting out of the scope box, like setting the variable as a thread-local variable, or searching the ObjectSpace.each_object, but those approaches are pretty bad in principal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following class class notify(): def __init__(self,server=localhost, port=23053): self.host = server self.port
I have the following Method: http_client=Net::HTTP.new(@uri.host,@uri.port) request=Net::HTTP::Post.new(@uri.request_uri) request.set_form_data(params) request.basic_auth(@user,@pass) result = http_client.request(request) # #
I have the following VB.net interface that I need to port to C#. C#
I have following situation - Have a MongoService class, which reads host, port, database
Hey community I have the following ServerSocket which should listen to port 53000 and
I copied the following script and run it to have it listen on port
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have the following code: try { //jaw-ws service port operation port.login(); } catch
I have the following code: $cluster['local'] = array('host' => '192.168.1.1', 'port' => '11211', 'weight'
i have the following main code: #include ComHandler.h #include socketMessage.h #define THIS_IP localhost #define

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.