|
1 | 1 | import paramiko |
| 2 | +import os |
2 | 3 | import re |
3 | 4 | import uuid |
4 | 5 | import logging |
@@ -280,6 +281,36 @@ def plaintext_login(self, username, password, private_key=""): |
280 | 281 |
|
281 | 282 | return True |
282 | 283 |
|
| 284 | + def put_file_single(self, sftp_conn, src, dst): |
| 285 | + self.logger.display(f'Copying "{src}" to "{dst}"') |
| 286 | + try: |
| 287 | + sftp_conn.put(src, dst) |
| 288 | + self.logger.success(f'Created file "{src}" on "{dst}"') |
| 289 | + except Exception as e: |
| 290 | + self.logger.fail(f'Error writing file to "{dst}": {e}') |
| 291 | + |
| 292 | + def put_file(self): |
| 293 | + sftp_conn = self.conn.open_sftp() |
| 294 | + for src, dest in self.args.put_file: |
| 295 | + self.put_file_single(sftp_conn, src, dest) |
| 296 | + sftp_conn.close() |
| 297 | + |
| 298 | + def get_file_single(self, sftp_conn, remote_path, download_path): |
| 299 | + self.logger.display(f'Copying "{remote_path}" to "{download_path}"') |
| 300 | + try: |
| 301 | + sftp_conn.get(remote_path, download_path) |
| 302 | + self.logger.success(f'File "{remote_path}" was downloaded to "{download_path}"') |
| 303 | + except Exception as e: |
| 304 | + self.logger.fail(f'Error getting file "{remote_path}": {e}') |
| 305 | + if os.path.getsize(download_path) == 0: |
| 306 | + os.remove(download_path) |
| 307 | + |
| 308 | + def get_file(self): |
| 309 | + sftp_conn = self.conn.open_sftp() |
| 310 | + for src, dest in self.args.get_file: |
| 311 | + self.get_file_single(sftp_conn, src, dest) |
| 312 | + sftp_conn.close() |
| 313 | + |
283 | 314 | def execute(self, payload=None, get_output=False): |
284 | 315 | if not payload and self.args.execute: |
285 | 316 | payload = self.args.execute |
|
0 commit comments