diff options
Diffstat (limited to 'python/remote.py')
| -rw-r--r-- | python/remote.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/python/remote.py b/python/remote.py index 5a886f01..9e08e8e6 100644 --- a/python/remote.py +++ b/python/remote.py @@ -7,9 +7,10 @@ from paramiko import Transport, SFTPClient, RSAKey from pathlib import Path from ssh2.session import Session from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR, LIBSSH2_SFTP_S_IFREG +from typing import Union -def load_credentials(name): +def load_credentials(name: str): return json.load((Path(".credentials") / f"{name}.json").open()) @@ -26,10 +27,13 @@ class FtpClient(Client): if folder is not None: self.client.cwd(folder) - def put(self, src: pathlib.Path, dst: str = None): - if dst is None: - dst = src.name - with src.open("rb") as fh: + def put(self, src: Union[pathlib.Path, bytes], dst: str = None): + if isinstance(src, pathlib.Path): + if dst is None: + dst = src.name + with src.open("rb") as fh: + self.client.storbinary(f"STOR {dst}", fh) + else: self.client.storbinary(f"STOR {dst}", fh) @@ -54,11 +58,14 @@ class SftpClient(Client): if not local_file.exists(): self.client.get(f"{src}/{f}", localpath=local_file) - def put(self, src: pathlib.Path, dst: str = None): - if dst is None: - dst = src.name - with src.open("rb") as fh: - self.client.putfo(fh, dst) + def put(self, src: Union[pathlib.Path, bytes], dst: str = None): + if isinstance(src, pathlib.Path): + if dst is None: + dst = src.name + with src.open("rb") as fh: + self.client.putfo(fh, dst) + else: + self.client.putfo(src, dst) class SftpClient2(Client): |
