librelist archives

« back to archive

Re: Can paramiko keep a ssh connection ?

Re: Can paramiko keep a ssh connection ?

From:
相勇
Date:
2014-01-19 @ 08:53
Sorry I didn't subscribe maillist before ,  subscribed and confirmed just
now


2014/1/19 相勇 <mailtoxiangyong@gmail.com>

> Hi, jeff & everybody :
>
>   I'm using paramiko 1.11.0. As all known if I ssh a server and don't do
> any operation for a long time, the server will disconnect the connection
> between us. So my question is can paramiko keep a ssh connection ?
>
> for example :
>
>   I connected remote server by paramiko successfully ,
> then time.sleep(some seconds) on my terminal , then exec_command with the
> object I've instanced . Should I check if the connection is closed before I
> use the object ? Or the object can keep connection by itself ?
>
> Thanks and Best Wishes !
>

Fwd: Can paramiko keep a ssh connection ?

From:
Jeff Forcier
Date:
2014-01-20 @ 07:16
(Re-sending to the ML...)

Hi,

You probably want to activate SSH's 'Keep-Alive' feature on the Transport class:

    http://docs.paramiko.org/paramiko.Transport-class.html#set_keepalive

You can see how Fabric does it here:

    
https://github.com/fabric/fabric/blob/8c1639344cabf12609aa09614bba2cc70b337d31/fabric/network.py#L450

Should be able to replicate that on your end; 'client' is just the
SSHClient instance, and replace 'env.keepalive' with an integer (in
seconds) of your choice.

Best,
Jeff

On Sun, Jan 19, 2014 at 12:53 AM, 相勇 <mailtoxiangyong@gmail.com> wrote:
> Sorry I didn't subscribe maillist before ,  subscribed and confirmed just
> now
>
>
> 2014/1/19 相勇 <mailtoxiangyong@gmail.com>
>>
>> Hi, jeff & everybody :
>>
>>   I'm using paramiko 1.11.0. As all known if I ssh a server and don't do
>> any operation for a long time, the server will disconnect the connection
>> between us. So my question is can paramiko keep a ssh connection ?
>>
>> for example :
>>
>>   I connected remote server by paramiko successfully , then
>> time.sleep(some seconds) on my terminal , then exec_command with the object
>> I've instanced . Should I check if the connection is closed before I use the
>> object ? Or the object can keep connection by itself ?
>>
>> Thanks and Best Wishes !
>
>
>
>



--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org

-- 
Jeff Forcier
Unix sysadmin; Python/Ruby developer
http://bitprophet.org