diff --git a/app.py b/app.py index cd27f63..34d8c55 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,8 @@ import scp import sys import math import re +import tempfile +import os envs = environ @@ -42,18 +44,27 @@ def strip_and_parse_envs(p): return None for c in strips: p = p.strip(c) - return path.expandvars(p) + return path.expandvars(p) if p != "." else f"{path.realpath(p)}/*" def connect(callback=None): - with paramiko.SSHClient() as ssh: - p_key = paramiko.RSAKey.from_private_key(INPUT_KEY) if INPUT_KEY else None + tmp = tempfile.NamedTemporaryFile(delete=False) + try: + ssh = paramiko.SSHClient() + p_key = None + if INPUT_KEY: + tmp.write(INPUT_KEY.encode()) + tmp.close() + p_key = paramiko.RSAKey.from_private_key_file(filename=tmp.name) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(INPUT_HOST, port=INPUT_PORT, username=INPUT_USER, pkey=p_key, password=INPUT_PASS, timeout=convert_to_seconds(INPUT_CONNECT_TIMEOUT)) if callback: callback(ssh) + finally: + os.unlink(tmp.name) + tmp.close() # Define progress callback that prints the current percentage completed for the file