feat(native): add SFTP client API - #426
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #426 +/- ##
==========================================
+ Coverage 99.53% 99.54% +0.01%
==========================================
Files 18 19 +1
Lines 1703 1758 +55
==========================================
+ Hits 1695 1750 +55
Misses 8 8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
pkittenis
left a comment
There was a problem hiding this comment.
Looks good as a first pass.
Would need to add a ParallelSFTPClient support for parallel operations, but for a single host SFTPClient this looks good.
Thank you for the PR, some minor changes needed for clarity and future parallel support.
| raise SFTPError(ex) | ||
| return sftp | ||
|
|
||
| def open_sftp(self): |
There was a problem hiding this comment.
Calling this make_sftp_client would be more explicit. open_sftp could also mean an ssh2.sftp.SFTP which will be confusing.
| """Create a remote directory and missing parent directories.""" | ||
| return self._client.mkdir(self._sftp, self._remote_path(path)) | ||
|
|
||
| def rmdir(self, path): |
There was a problem hiding this comment.
Recursion would be nice to have here, but can be added later.
| with self._client._sftp_openfh( | ||
| self._sftp.opendir, self._remote_path(path)) as dir_h: | ||
| entries = self._client._sftp_readdir(dir_h) | ||
| names = [entry.decode(encoding) for entry in entries] |
There was a problem hiding this comment.
| names = [entry.decode(encoding) for entry in entries] | |
| names = (entry.decode(encoding) for entry in entries if entry not in ('.', '..')) | |
| for name in names: | |
| yield name |
Returning a generator allows other greenlets to run while this is blocked, which will be needed for a ParallelSFTPClient.
Also matches the rest of the API which returns generators.
| self._sftp.opendir, self._remote_path(path)) as dir_h: | ||
| entries = self._client._sftp_readdir(dir_h) | ||
| names = [entry.decode(encoding) for entry in entries] | ||
| return [name for name in names if name not in ('.', '..')] |
There was a problem hiding this comment.
Should be removed in favour of generator.
Summary
SFTPClientopened throughSSHClient.open_sftp()SSHClientSFTP methods compatible and document native-only supportVerification
flake8 pssh tests ci/integration_testsorigin/master: no new failuresCloses #410.