From 619ddbddb66a30e8cef37eeec85b3dbe07aa5d70 Mon Sep 17 00:00:00 2001 From: Shashank Gopikrishna Date: Tue, 18 Aug 2026 10:51:01 -0400 Subject: [PATCH 1/4] fix compression - apply default compression if enabled but method not provided --- sftpretty/__init__.py | 5 +++-- tests/test_compression.py | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sftpretty/__init__.py b/sftpretty/__init__.py index 2e34ae25..98cc1352 100644 --- a/sftpretty/__init__.py +++ b/sftpretty/__init__.py @@ -450,8 +450,9 @@ def _start_transport(self, host, port): log.debug(f'Ciphers: [{ciphers}]') # Set compression algorithms compression = self._cnopts.compression - self._transport.get_security_options().compression = compression - log.debug(f'Compression: [{compression}]') + if bool(compress) and compression != ('none',): + self._transport.get_security_options().compression = compression + log.debug(f'Compression: [{self._transport.get_security_options().compression}]') # Set connection digests digests = self._config.get('macs') or self._cnopts.digests _digests = self._transport.get_security_options().digests diff --git a/tests/test_compression.py b/tests/test_compression.py index e66f53dd..e2da5a0d 100644 --- a/tests/test_compression.py +++ b/tests/test_compression.py @@ -1,6 +1,6 @@ '''test sftpretty.compression param''' -from common import LOCAL, SKIP_IF_CI +from common import LOCAL from sftpretty import CnOpts, Connection @@ -10,7 +10,6 @@ def test_compression_default(): assert sftp.active_compression == ('none', 'none') -@SKIP_IF_CI def test_compression_enabled(): '''test that compress=True results in compression enabled, assuming that the server supports compression''' From 370cda9a18812749ccd63b342a09008d0dd96cfe Mon Sep 17 00:00:00 2001 From: Shashank Gopikrishna Date: Tue, 18 Aug 2026 11:00:34 -0400 Subject: [PATCH 2/4] avoid calling self._transport.get_security_options() many times - Also fixes pep8 linewidth --- sftpretty/__init__.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sftpretty/__init__.py b/sftpretty/__init__.py index 98cc1352..0c49d29a 100644 --- a/sftpretty/__init__.py +++ b/sftpretty/__init__.py @@ -440,42 +440,43 @@ def _start_transport(self, host, port): log.debug(f'Disabled Algorithms: [{disabled_algorithms}]') # Security Options + security_options = self._transport.get_security_options() # Set allowed ciphers ciphers = self._config.get('ciphers') or self._cnopts.ciphers - _ciphers = self._transport.get_security_options().ciphers + _ciphers = security_options.ciphers if not isinstance(ciphers, tuple): ciphers = tuple(ciphers.split(',')) - self._transport.get_security_options().ciphers = tuple( + security_options.ciphers = tuple( cipher for cipher in ciphers if cipher in _ciphers) log.debug(f'Ciphers: [{ciphers}]') # Set compression algorithms compression = self._cnopts.compression if bool(compress) and compression != ('none',): - self._transport.get_security_options().compression = compression - log.debug(f'Compression: [{self._transport.get_security_options().compression}]') + security_options.compression = compression + log.debug(f'Compression: [{security_options.compression}]') # Set connection digests digests = self._config.get('macs') or self._cnopts.digests - _digests = self._transport.get_security_options().digests + _digests = security_options.digests if not isinstance(digests, tuple): digests = tuple(digests.split(',')) - self._transport.get_security_options().digests = tuple( + security_options.digests = tuple( digest for digest in digests if digest in _digests) log.debug(f'MACs: [{digests}]') # Set connection kex kexs = self._config.get('kexalgorithms') or self._cnopts.kex - _kex = self._transport.get_security_options().kex + _kex = security_options.kex if not isinstance(kexs, tuple): kexs = tuple(kexs.split(',')) - self._transport.get_security_options().kex = tuple( + security_options.kex = tuple( kex for kex in kexs if kex in _kex) log.debug(f'KEX: [{kexs}]') # Set allowed key types key_types = self._config.get('pubkeyacceptedalgorithms') or\ self._cnopts.key_types - _key_types = self._transport.get_security_options().key_types + _key_types = security_options.key_types if not isinstance(key_types, tuple): key_types = tuple(key_types.split(',')) - self._transport.get_security_options().key_types = tuple( + security_options.key_types = tuple( key_type for key_type in key_types if key_type in _key_types) log.debug(f'Public Key Types: [{key_types}]') From 61c8b749fcb53f5b34508adbc1ea36fd3cf5c141 Mon Sep 17 00:00:00 2001 From: Shashank Gopikrishna Date: Fri, 21 Aug 2026 21:02:50 -0400 Subject: [PATCH 3/4] perform enabling compression and setting compression algo steps one after the other for better readability --- sftpretty/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sftpretty/__init__.py b/sftpretty/__init__.py index 0c49d29a..cd3dca95 100644 --- a/sftpretty/__init__.py +++ b/sftpretty/__init__.py @@ -431,9 +431,6 @@ def _start_transport(self, host, port): self._transport.set_keepalive(int(keepalive)) self._transport.set_log_channel(host) - compress = self._config.get('compression') or self._cnopts.compress - self._transport.use_compression(compress=bool(compress)) - # Set disabled algorithms disabled_algorithms = self._cnopts.disabled_algorithms self._transport.disabled_algorithms = disabled_algorithms @@ -449,6 +446,9 @@ def _start_transport(self, host, port): security_options.ciphers = tuple( cipher for cipher in ciphers if cipher in _ciphers) log.debug(f'Ciphers: [{ciphers}]') + # Enable/Disable compression + compress = self._config.get('compression') or self._cnopts.compress + self._transport.use_compression(compress=bool(compress)) # Set compression algorithms compression = self._cnopts.compression if bool(compress) and compression != ('none',): From be787e769b3d5c58d84e7db14a6993eb37bbbac9 Mon Sep 17 00:00:00 2001 From: byteskeptical <40208858+byteskeptical@users.noreply.github.com> Date: Mon, 7 Sep 2026 02:05:02 +0000 Subject: [PATCH 4/4] moving compress out of the security options settings and with the other transport settings --- sftpretty/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sftpretty/__init__.py b/sftpretty/__init__.py index e186ee8c..6fa7f5dc 100644 --- a/sftpretty/__init__.py +++ b/sftpretty/__init__.py @@ -440,6 +440,11 @@ def _start_transport(self, host, port): self._transport.set_keepalive(int(keepalive)) self._transport.set_log_channel(host) + # Set compression + compress = self._config.get('compression') or self._cnopts.compress + self._transport.use_compression(compress=bool(compress)) + log.debug(f'Compress: [{compress}]') + # Set disabled algorithms disabled_algorithms = self._cnopts.disabled_algorithms self._transport.disabled_algorithms = disabled_algorithms @@ -455,9 +460,6 @@ def _start_transport(self, host, port): security_options.ciphers = tuple( cipher for cipher in ciphers if cipher in _ciphers) log.debug(f'Ciphers: [{ciphers}]') - # Enable/Disable compression - compress = self._config.get('compression') or self._cnopts.compress - self._transport.use_compression(compress=bool(compress)) # Set compression algorithms compression = self._cnopts.compression if bool(compress) and compression != ('none',):