mirror of
https://gitee.com/jack_whh/ssh-scp-ssh-pipelines.git
synced 2026-03-09 22:42:55 +08:00
fix '.' and connection per key
This commit is contained in:
17
app.py
17
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
|
||||
|
||||
Reference in New Issue
Block a user