@@ -74,13 +74,14 @@ def __init__(self, config=None, knownhosts=Path(
7474 'hmac-sha1' , 'hmac-md5' )
7575 self .disabled_algorithms = {}
7676 self .hostkeys = hostkeys .HostKeys ()
77- self .kex = ('ecdh-sha2-nistp521' , 'ecdh-sha2-nistp384' ,
78- 'ecdh-sha2-nistp256' , 'diffie-hellman-group16-sha512' ,
77+ self .kex = ('curve25519-sha256@libssh.org' , 'ecdh-sha2-nistp521' ,
78+ 'ecdh-sha2-nistp384' , 'ecdh-sha2-nistp256' ,
79+ 'diffie-hellman-group16-sha512' ,
7980 'diffie-hellman-group-exchange-sha256' ,
80- 'diffie-hellman-group-exchange-sha1 ' )
81+ 'diffie-hellman-group14-sha256 ' )
8182 self .key_types = ('ssh-ed25519' , 'ecdsa-sha2-nistp521' ,
8283 'ecdsa-sha2-nistp384' , 'ecdsa-sha2-nistp256' ,
83- 'rsa-sha2-512' , 'rsa-sha2-256' , 'ssh-rsa' )
84+ 'rsa-sha2-512' , 'rsa-sha2-256' )
8485 self .log = False
8586 self .log_level = 'info'
8687 self .ssh_config = SSHConfig ()
@@ -300,24 +301,26 @@ def _sftp_channel(self):
300301 channel = None
301302 fatal = False
302303
304+ self ._cache .__dict__ .setdefault ('cwd' , self ._default_path )
305+
303306 try :
304307 channel_name , data = next (
305308 (key , value )
306309 for key , value in self ._channels .items ()
307- if not value ['busy' ]
310+ if not value ['busy' ] and not value [ 'meta' ]. closed
308311 )
312+
313+ channel = data ['channel' ]
309314 meta = data ['meta' ]
310- if not meta .closed :
311- channel = data ['channel' ]
312- self ._channels [channel_name ]['busy' ] = True
313- log .debug (f'Cached Channel: [{ channel_name } ]' )
315+ self ._channels [channel_name ]['busy' ] = True
316+ log .debug (f'Cached Channel: [{ channel_name } ]' )
314317 except StopIteration :
315318 pass
316319
317320 try :
318321 if channel is None :
319- channel = SFTPClient .from_transport (self ._transport )
320322 channel_name = uuid4 ().hex
323+ channel = SFTPClient .from_transport (self ._transport )
321324 meta = channel .get_channel ()
322325 meta .set_name (channel_name )
323326 log .debug (f'Channel Name: [{ channel_name } ]' )
@@ -326,7 +329,6 @@ def _sftp_channel(self):
326329 }
327330
328331 meta .settimeout (self ._timeout )
329- self ._cache .__dict__ .setdefault ('cwd' , self ._default_path )
330332
331333 if self ._cache .cwd is None :
332334 self ._cache .cwd = drivedrop (channel .normalize ('.' ))
@@ -344,6 +346,7 @@ def _sftp_channel(self):
344346 log .error (_message )
345347 raise TimeoutError (_message )
346348 except SFTPError as err :
349+ code = err .args [0 ] if err .args else None
347350 _message_map = {
348351 SFTP_FAILURE : (
349352 'A generic failure occurred on the SFTP server for path: '
@@ -361,9 +364,9 @@ def _sftp_channel(self):
361364 ),
362365 }
363366 _message = _message_map .get (
364- err . errno ,
367+ code ,
365368 ('Unhandled SFTP error on directory change to '
366- f'[{ self ._cache .cwd } ] (Code { err . errno } ): { err } ' )
369+ f'[{ self ._cache .cwd } ] (Code { code } ): { err } ' )
367370 )
368371 log .error (_message )
369372 raise err
0 commit comments