[paramiko] How to use settimeout with from_transport
James Bardin
jbardin at bu.edu
Thu Mar 15 14:13:58 PDT 2007
I've wondered how to do this myself, and I have a method that works, but
maybe someone will let us know if there's a better way.
My program uses a large number of connections simultaneously, so to set
a short timeout for everything I do the following:
from socket import setdefaulttimeout
setdefaulttimeout(2)
This setting propagates up and is used by the sockets created by paramiko.
If it makes a difference, I'm building my connection with:
client = SSHClient()
client.connect(...)
sftp = client.open_sftp()
-jim
Manpreet Singh Khurana wrote:
> Hi
> I have a simple utility which opens SSH connection to remote server by using
>
> t = paramiko.Transport((hostname, port))
> and then doing connect by
>
> t.connect(username=username, password=password, hostkey=hostkey)
>
> The i am using SFTPClient to open an sftp session across an open ssh
> Transport and do remote file operations.
> sftp = paramiko.SFTPClient.from_transport(t)
>
> Now with this SFTP Client object i am opening a file on the remote server
> rPath= sftp.file(fileName, 'rb')
> and reading the file from this path
> data = rPath.read(32768)
>
> Now I want to use the settimeout API to set the timeout value of this
> socket so that id the read operation takes time more than the
> configured value we should be
> able to timeout that socket
>
> How can this be done
> Can i use sftp.settimeout(60) directly
> Do we have a sample code to understand the usage
> Can somebody tell me how this is done.
> This is urgent, please help.
>
> MSK
>
> _______________________________________________
> paramiko mailing list
> paramiko at lag.net
> http://mail.lag.net/mailman/listinfo/paramiko
>
>
More information about the paramiko
mailing list