fix '.' and connection per key

master v1.1.2
Nguyen Huu Thuong 5 years ago
parent 4a07cd477b
commit e1c2bf0c8d

@ -6,6 +6,8 @@ import scp
import sys import sys
import math import math
import re import re
import tempfile
import os
envs = environ envs = environ
@ -42,18 +44,27 @@ def strip_and_parse_envs(p):
return None return None
for c in strips: for c in strips:
p = p.strip(c) p = p.strip(c)
return path.expandvars(p) return path.expandvars(p) if p != "." else f"{path.realpath(p)}/*"
def connect(callback=None): def connect(callback=None):
with paramiko.SSHClient() as ssh: tmp = tempfile.NamedTemporaryFile(delete=False)
p_key = paramiko.RSAKey.from_private_key(INPUT_KEY) if INPUT_KEY else None 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.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(INPUT_HOST, port=INPUT_PORT, username=INPUT_USER, ssh.connect(INPUT_HOST, port=INPUT_PORT, username=INPUT_USER,
pkey=p_key, password=INPUT_PASS, pkey=p_key, password=INPUT_PASS,
timeout=convert_to_seconds(INPUT_CONNECT_TIMEOUT)) timeout=convert_to_seconds(INPUT_CONNECT_TIMEOUT))
if callback: if callback:
callback(ssh) callback(ssh)
finally:
os.unlink(tmp.name)
tmp.close()
# Define progress callback that prints the current percentage completed for the file # Define progress callback that prints the current percentage completed for the file

Loading…
Cancel
Save