mirror of
https://gitee.com/jack_whh/ssh-scp-ssh-pipelines.git
synced 2026-03-15 01:02:57 +08:00
feat: add exceptions handling
This commit is contained in:
committed by
GitHub
parent
e1c2bf0c8d
commit
d5d6f7b3cb
27
app.py
27
app.py
@@ -60,8 +60,14 @@ def connect(callback=None):
|
|||||||
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))
|
||||||
|
except:
|
||||||
|
print("Connect error")
|
||||||
|
raise
|
||||||
|
|
||||||
|
else:
|
||||||
if callback:
|
if callback:
|
||||||
callback(ssh)
|
callback(ssh)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
os.unlink(tmp.name)
|
os.unlink(tmp.name)
|
||||||
tmp.close()
|
tmp.close()
|
||||||
@@ -98,10 +104,8 @@ def ssh_process(ssh, input_ssh):
|
|||||||
err = "".join(stderr.readlines())
|
err = "".join(stderr.readlines())
|
||||||
err = err.strip() if err is not None else None
|
err = err.strip() if err is not None else None
|
||||||
if err:
|
if err:
|
||||||
if out is None:
|
print(f"Error: \n{err}")
|
||||||
raise Exception(err)
|
raise Exception(err)
|
||||||
else:
|
|
||||||
print(f"Error: \n{err}")
|
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -128,10 +132,19 @@ def scp_process(ssh, input_scp):
|
|||||||
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
|
with scp.SCPClient(ssh.get_transport(), progress=progress, sanitize=lambda x: x) as conn:
|
||||||
for l2r in copy_list:
|
for l2r in copy_list:
|
||||||
remote = l2r.get('r')
|
remote = l2r.get('r')
|
||||||
ssh.exec_command(f"mkdir -p {remote} || true")
|
try:
|
||||||
|
ssh.exec_command(f"mkdir -p {remote}")
|
||||||
|
except:
|
||||||
|
print(f"Remote mkdir error. Can't create {remote}")
|
||||||
|
raise
|
||||||
|
|
||||||
for f in [f for f in glob(l2r.get('l'))]:
|
for f in [f for f in glob(l2r.get('l'))]:
|
||||||
conn.put(f, remote_path=remote, recursive=True)
|
try:
|
||||||
print(f"{f} -> {remote}")
|
conn.put(f, remote_path=remote, recursive=True)
|
||||||
|
print(f"{f} -> {remote}")
|
||||||
|
except:
|
||||||
|
print(f"scp error. Can't copy {f} on {remote}")
|
||||||
|
raise
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user