2727from ssh2 .error_codes import LIBSSH2_ERROR_EAGAIN
2828from ssh2 .exceptions import SFTPHandleError , SFTPProtocolError , \
2929 Timeout as SSH2Timeout
30- from ssh2 .session import Session , LIBSSH2_SESSION_BLOCK_INBOUND , LIBSSH2_SESSION_BLOCK_OUTBOUND
30+ from ssh2 .session import Session , LIBSSH2_SESSION_BLOCK_INBOUND , LIBSSH2_SESSION_BLOCK_OUTBOUND , LIBSSH2_FLAG_COMPRESS
3131from ssh2 .sftp import LIBSSH2_FXF_READ , LIBSSH2_FXF_CREAT , LIBSSH2_FXF_WRITE , \
3232 LIBSSH2_FXF_TRUNC , LIBSSH2_SFTP_S_IRUSR , LIBSSH2_SFTP_S_IRGRP , \
3333 LIBSSH2_SFTP_S_IWUSR , LIBSSH2_SFTP_S_IXUSR , LIBSSH2_SFTP_S_IROTH , \
@@ -110,6 +110,7 @@ def __init__(self, host,
110110 keepalive_seconds = 60 ,
111111 identity_auth = True ,
112112 ipv6_only = False ,
113+ compress = False ,
113114 ):
114115 """
115116 :param host: Host name or IP to connect to.
@@ -158,6 +159,8 @@ def __init__(self, host,
158159 for the host or raise NoIPv6AddressFoundError otherwise. Note this will
159160 disable connecting to an IPv4 address if an IP address is provided instead.
160161 :type ipv6_only: bool
162+ :param compress: Enable/Disable compression on the client. Defaults to off.
163+ :type compress: bool
161164
162165 :raises: :py:class:`pssh.exceptions.PKeyFileError` on errors finding
163166 provided private key.
@@ -182,6 +185,7 @@ def __init__(self, host,
182185 timeout = timeout ,
183186 keepalive_seconds = keepalive_seconds ,
184187 identity_auth = identity_auth ,
188+ compress = compress ,
185189 )
186190 proxy_host = '127.0.0.1'
187191 self ._chan_stdout_lock = RLock ()
@@ -194,6 +198,7 @@ def __init__(self, host,
194198 proxy_host = proxy_host , proxy_port = proxy_port ,
195199 identity_auth = identity_auth ,
196200 ipv6_only = ipv6_only ,
201+ compress = compress ,
197202 )
198203
199204 def _shell (self , channel ):
@@ -206,7 +211,9 @@ def _connect_proxy(self, proxy_host, proxy_port, proxy_pkey,
206211 allow_agent = True , timeout = None ,
207212 forward_ssh_agent = False ,
208213 keepalive_seconds = 60 ,
209- identity_auth = True ):
214+ identity_auth = True ,
215+ compress = False ,
216+ ):
210217 assert isinstance (self .port , int )
211218 try :
212219 self ._proxy_client = SSHClient (
@@ -216,6 +223,7 @@ def _connect_proxy(self, proxy_host, proxy_port, proxy_pkey,
216223 timeout = timeout , forward_ssh_agent = forward_ssh_agent ,
217224 identity_auth = identity_auth ,
218225 keepalive_seconds = keepalive_seconds ,
226+ compress = compress ,
219227 _auth_thread_pool = False )
220228 except Exception as ex :
221229 msg = "Proxy authentication failed. " \
@@ -263,6 +271,8 @@ def configure_keepalive(self):
263271
264272 def _init_session (self , retries = 1 ):
265273 self .session = Session ()
274+ if self .compress :
275+ self .session .flag (LIBSSH2_FLAG_COMPRESS )
266276
267277 if self .timeout :
268278 # libssh2 timeout is in ms
0 commit comments