Skip to content

Commit

Permalink
Updates for latest ssh2-python release. Added agent forwarding compil…
Browse files Browse the repository at this point in the history
…e time flag.
  • Loading branch information
Pan committed May 30, 2018
1 parent c5b5790 commit a7fdf17
Show file tree
Hide file tree
Showing 8 changed files with 589 additions and 406 deletions.
15 changes: 14 additions & 1 deletion Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
Change Log
============

1.6.3
++++++

Changes
--------

* Re-generated C code with latest Cython release.

Fixes
------

* ``ssh2-python`` >= 0.14.0 support.

1.6.2
++++++

Fixes
------

* Native client proxy initilisation failures were not caught by ``stop_on_errors=False`` - #121.
* Native client proxy initialisation failures were not caught by ``stop_on_errors=False`` - #121.

1.6.1
+++++++
Expand Down
27 changes: 10 additions & 17 deletions pssh/clients/native/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from gevent import sleep, socket, get_hub
from gevent.hub import Hub
from ssh2.error_codes import LIBSSH2_ERROR_EAGAIN
from ssh2.exceptions import SFTPHandleError, \
SFTPIOError as SFTPIOError_ssh2
from ssh2.exceptions import SFTPHandleError, SFTPProtocolError
from ssh2.session import Session
from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_FXF_CREAT, LIBSSH2_FXF_WRITE, \
LIBSSH2_FXF_TRUNC, LIBSSH2_SFTP_S_IRUSR, LIBSSH2_SFTP_S_IRGRP, \
Expand Down Expand Up @@ -416,18 +415,12 @@ def _make_sftp(self):
sftp = self.session.sftp_init()
except Exception as ex:
raise SFTPError(ex)
errno = self.session.last_errno()
while (sftp is None and errno == LIBSSH2_ERROR_EAGAIN) \
or sftp == LIBSSH2_ERROR_EAGAIN:
while sftp == LIBSSH2_ERROR_EAGAIN:
wait_select(self.session)
try:
sftp = self.session.sftp_init()
except Exception as ex:
raise SFTPError(ex)
errno = self.session.last_errno()
if sftp is None and errno != LIBSSH2_ERROR_EAGAIN:
raise SFTPError("Error initialising SFTP - error code %s",
errno)
return sftp

def _mkdir(self, sftp, directory):
Expand All @@ -449,7 +442,7 @@ def _mkdir(self, sftp, directory):
LIBSSH2_SFTP_S_IXOTH
try:
self._eagain(sftp.mkdir, directory, mode)
except SFTPIOError_ssh2 as error:
except SFTPProtocolError as error:
msg = "Error occured creating directory %s on host %s - %s"
logger.error(msg, directory, self.host, error)
raise SFTPIOError(msg, directory, self.host, error)
Expand Down Expand Up @@ -485,7 +478,7 @@ def copy_file(self, local_file, remote_file, recurse=False,
if destination is not None:
try:
self._eagain(sftp.stat, destination)
except SFTPHandleError:
except (SFTPHandleError, SFTPProtocolError):
self.mkdir(sftp, destination)
self.sftp_put(sftp, local_file, remote_file)
logger.info("Copied local file %s to remote destination %s:%s",
Expand All @@ -508,7 +501,7 @@ def sftp_put(self, sftp, local_file, remote_file):
self._sftp_put(remote_fh, local_file)
# THREAD_POOL.apply(
# sftp_put, args=(self.session, remote_fh, local_file))
except SFTPIOError_ssh2 as ex:
except SFTPProtocolError as ex:
msg = "Error writing to remote file %s - %s"
logger.error(msg, remote_file, ex)
raise SFTPIOError(msg, remote_file, ex)
Expand Down Expand Up @@ -539,7 +532,7 @@ def mkdir(self, sftp, directory, _parent_path=None):
_dir = '/'.join((_parent_path, _dir))
try:
self._eagain(sftp.stat, _dir)
except SFTPHandleError as ex:
except (SFTPHandleError, SFTPProtocolError) as ex:
logger.debug("Stat for %s failed with %s", _dir, ex)
self._mkdir(sftp, _dir)
if sub_dirs is not None:
Expand Down Expand Up @@ -582,7 +575,7 @@ def copy_remote_file(self, remote_file, local_file, recurse=False,
sftp = self._make_sftp() if sftp is None else sftp
try:
self._eagain(sftp.stat, remote_file)
except SFTPHandleError:
except (SFTPHandleError, SFTPProtocolError):
msg = "Remote file or directory %s does not exist"
logger.error(msg, remote_file)
raise SFTPIOError(msg, remote_file)
Expand Down Expand Up @@ -635,7 +628,7 @@ def scp_recv(self, remote_file, local_file, recurse=False, sftp=None,
if recurse:
try:
self._eagain(sftp.stat, remote_file)
except SFTPHandleError:
except (SFTPHandleError, SFTPProtocolError):
msg = "Remote file or directory %s does not exist"
logger.error(msg, remote_file)
raise SCPError(msg, remote_file)
Expand Down Expand Up @@ -744,7 +737,7 @@ def scp_send(self, local_file, remote_file, recurse=False, sftp=None):
sftp = self._make_sftp() if sftp is None else sftp
try:
self._eagain(sftp.stat, destination)
except SFTPHandleError:
except (SFTPHandleError, SFTPProtocolError):
self.mkdir(sftp, destination)
self._scp_send(local_file, remote_file)
logger.info("SCP local file %s to remote destination %s:%s",
Expand Down Expand Up @@ -807,7 +800,7 @@ def sftp_get(self, sftp, remote_file, local_file):
# cannot be used simultaneously in multiple threads.
# THREAD_POOL.apply(
# sftp_get, args=(self.session, remote_fh, local_file))
except SFTPIOError_ssh2 as ex:
except SFTPProtocolError as ex:
msg = "Error reading from remote file %s - %s"
logger.error(msg, remote_file, ex)
raise SFTPIOError(msg, remote_file, ex)
Expand Down
Loading

0 comments on commit a7fdf17

Please sign in to comment.