[paramiko] Suggested addition to get channel from SSHClient (with patch)

Paul Rouse p.rouse at rms.co.uk
Tue Oct 23 06:25:25 PDT 2007


This is a suggestion that SSHClient should provide methods
for opening channels of any types (not just one on which a shell
has been invoked).

My reason is this: arguably the most useful service provided by
SSHClient is its high-level handling of the SSH connection,
particularly authentication.  Once set up, though, there is
sometimes a need to have more control over the channels, for
example setting timeouts or merging stderr with stdout.

It seems a shame to abandon the authentication aspects of SSHClient 
simply so that arbitrary channels can be opened (and it is
probably even worse to get round it by accessing its private
_transport attribute!)

I have included a patch which simply exposes channel-creation
methods on the underlying Transport.  The alternative would
be to provide direct access to the Transport, but to me that
alternative does seem to cut too much across the levels.

    - Paul Rouse

--- client.py	2007-10-23 12:30:07.000000000 +0100
+++ ../../paramiko-copy/client.py	2007-10-19 10:32:45.000000000 +0100
@@ -348,6 +348,39 @@
         @rtype: L{SFTPClient}
         """
         return self._transport.open_sftp_client()
+
+    def open_channel (self, kind, dest_addr=None, src_addr=None):
+        """Request a new channel to the server.  L{Channel}s are socket-like
+           objects used for the actual transfer of data across the session.
+           
+           This method simply calls
+           L{open_channel<paramiko.Transport.open_channel>}
+           on the underlying L{transport<paramiko.Transport>}, and has
+           the same parameters and results.
+        """
+        return self._transport.open_channel (kind, dest_addr, src_addr)
+
+    def open_x11_channel (self, src_addr=None):
+        """Request a new channel to the client, of type C{"x11"}.  This
+           is equivalent to C{open_channel('x11', src_addr=src_addr)}.
+           
+           This method simply calls
+           L{open_x11_channel<paramiko.Transport.open_x11_channel>}
+           on the underlying L{transport<paramiko.Transport>}, and has
+           the same parameters and results.
+        """
+        return self._transport.open_x11_channel (src_addr)
+
+    def open_session (self):
+        """Request a new channel to the server, of type C{"session"}.  This
+           is equivalent to C{open_channel('session')}.
+           
+           This method simply calls
+           L{open_session<paramiko.Transport.open_session>}
+           on the underlying L{transport<paramiko.Transport>}, and has
+           the same parameters and results.
+        """
+        return self._transport.open_session ()
         
     def _auth(self, username, password, pkey, key_filename):
         """

 

_____________________________________________________________________
This message has been checked for all known viruses by the 
RMS Services Ltd Virus Scanning Service. For further information visit
http://www.rms.co.uk or call UK 01454 281265
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.txt
Url: http://www.lag.net/pipermail/paramiko/attachments/20071023/0df561a2/attachment.txt 


More information about the paramiko mailing list