Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions doc/source/SSHClient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ API: SSHClient and SSHAuth.
:type path: ``str``
:return: path is valid (object exists)
:rtype: ``bool``
:raises ConnectionError: SSH session was closed and the reconnect failed
:raises OSError: SSH session was closed and the reconnect failed with a socket error
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error

.. versionchanged:: 8.2.2 a failed reconnect is raised instead of being reported as a missing path

.. py:method:: stat(path)

Expand Down Expand Up @@ -477,6 +482,11 @@ API: SSHClient and SSHAuth.
:type path: ``str``
:return: path is file
:rtype: ``bool``
:raises ConnectionError: SSH session was closed and the reconnect failed
:raises OSError: SSH session was closed and the reconnect failed with a socket error
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error

.. versionchanged:: 8.2.2 a failed reconnect is raised instead of being reported as a missing path

.. py:method:: isdir(path)

Expand All @@ -486,6 +496,11 @@ API: SSHClient and SSHAuth.
:type path: ``str``
:return: path is directory
:rtype: ``bool``
:raises ConnectionError: SSH session was closed and the reconnect failed
:raises OSError: SSH session was closed and the reconnect failed with a socket error
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error

.. versionchanged:: 8.2.2 a failed reconnect is raised instead of being reported as a missing path

.. py:method:: islink(path)

Expand All @@ -495,6 +510,11 @@ API: SSHClient and SSHAuth.
:type path: ``str``
:return: path is symlink
:rtype: ``bool``
:raises ConnectionError: SSH session was closed and the reconnect failed
:raises OSError: SSH session was closed and the reconnect failed with a socket error
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error

.. versionchanged:: 8.2.2 a failed reconnect is raised instead of being reported as a missing path

.. py:method:: symlink(source, dest)

Expand Down Expand Up @@ -535,6 +555,8 @@ API: SSHClient and SSHAuth.
:type source: ``str``
:type target: ``str``

.. versionchanged:: 8.2.2 uploading a directory creates the remote directory it is copied to

.. py:method:: download(destination, target)

Download file(s) to target from destination.
Expand Down
32 changes: 28 additions & 4 deletions exec_helpers/_ssh_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,9 +1905,15 @@ def exists(self, path: SupportPathT) -> bool:
:type path: str | pathlib.PurePath
:return: path is valid (an object exists).
:rtype: bool
:raises ConnectionError: SSH session was closed and the reconnect failed.
:raises OSError: SSH session was closed and the reconnect failed with a socket error.
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error.

.. versionchanged:: 8.2.2 A failed reconnect is raised instead of being reported as a missing path.
"""
sftp = self._sftp # a failed reconnect is raised, not reported as a missing path
try:
self._sftp.lstat(pathlib.PurePath(path).as_posix())
sftp.lstat(pathlib.PurePath(path).as_posix())
except OSError:
return False

Expand Down Expand Up @@ -1942,9 +1948,15 @@ def isfile(self, path: SupportPathT) -> bool:
:type path: str | pathlib.PurePath
:return: path is file.
:rtype: bool
:raises ConnectionError: SSH session was closed and the reconnect failed.
:raises OSError: SSH session was closed and the reconnect failed with a socket error.
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error.

.. versionchanged:: 8.2.2 A failed reconnect is raised instead of being reported as a missing path.
"""
sftp = self._sftp # a failed reconnect is raised, not reported as a missing path
try:
attrs: paramiko.sftp_attr.SFTPAttributes = self._sftp.lstat(pathlib.PurePath(path).as_posix())
attrs: paramiko.sftp_attr.SFTPAttributes = sftp.lstat(pathlib.PurePath(path).as_posix())
if attrs.st_mode is None:
return False
return stat.S_ISREG(attrs.st_mode)
Expand All @@ -1958,9 +1970,15 @@ def isdir(self, path: SupportPathT) -> bool:
:type path: str | pathlib.PurePath
:return: path is directory.
:rtype: bool
:raises ConnectionError: SSH session was closed and the reconnect failed.
:raises OSError: SSH session was closed and the reconnect failed with a socket error.
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error.

.. versionchanged:: 8.2.2 A failed reconnect is raised instead of being reported as a missing path.
"""
sftp = self._sftp # a failed reconnect is raised, not reported as a missing path
try:
attrs: paramiko.sftp_attr.SFTPAttributes = self._sftp.lstat(pathlib.PurePath(path).as_posix())
attrs: paramiko.sftp_attr.SFTPAttributes = sftp.lstat(pathlib.PurePath(path).as_posix())
if attrs.st_mode is None:
return False
return stat.S_ISDIR(attrs.st_mode)
Expand All @@ -1974,9 +1992,15 @@ def islink(self, path: SupportPathT) -> bool:
:type path: str | pathlib.PurePath
:return: path is symlink.
:rtype: bool
:raises ConnectionError: SSH session was closed and the reconnect failed.
:raises OSError: SSH session was closed and the reconnect failed with a socket error.
:raises paramiko.SSHException: SFTP connection failed, or the reconnect failed with a paramiko error.

.. versionchanged:: 8.2.2 A failed reconnect is raised instead of being reported as a missing path.
"""
sftp = self._sftp # a failed reconnect is raised, not reported as a missing path
try:
attrs: paramiko.sftp_attr.SFTPAttributes = self._sftp.lstat(pathlib.PurePath(path).as_posix())
attrs: paramiko.sftp_attr.SFTPAttributes = sftp.lstat(pathlib.PurePath(path).as_posix())
if attrs.st_mode is None:
return False
return stat.S_ISLNK(attrs.st_mode)
Expand Down
3 changes: 3 additions & 0 deletions exec_helpers/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def upload(self, source: SupportPathT, target: SupportPathT) -> None:
:type source: str | pathlib.PurePath
:param target: Remote path.
:type target: str | pathlib.PurePath

.. versionchanged:: 8.2.2 Uploading a directory creates the remote directory it is copied to.
"""
self.logger.debug(f"Copying '{source}' -> '{target}'")

Expand All @@ -87,6 +89,7 @@ def upload(self, source: SupportPathT, target: SupportPathT) -> None:
self._sftp.put(src.as_posix(), tgt.as_posix(), confirm=True)
return

self.mkdir(tgt.as_posix()) # glob below yields only what is inside src, never src itself
for pth in src.glob("**/*"):
relative = pth.relative_to(src).as_posix()
destination: str = os.path.normpath(tgt.joinpath(relative).as_posix()).replace("\\", "/")
Expand Down
Loading
Loading