-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathssh.py
More file actions
42 lines (31 loc) · 1.19 KB
/
ssh.py
File metadata and controls
42 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
import tasks
def run(user, password, host, command):
"""
Execute a command in a remote host
"""
remote_command = f"sshpass -p {password} ssh -o StrictHostKeyChecking=no {user}@{host} {command}"
return tasks.run(remote_command)
def copy_to_host(user, password, host, origin, destination):
"""
Copy a local directory to a remote host
"""
command = f"sshpass -p {password} scp -o StrictHostKeyChecking=no -r {origin} {user}@{host}:{destination}"
return tasks.run(command)
def copy_from_host(user, password, host, origin, destination):
"""
Copy to a local directory from a remote host
"""
command = f"sshpass -p {password} scp -o StrictHostKeyChecking=no -r {user}@{host}:{origin} {destination}"
return tasks.run(command)
def safe_copy_to_host(user, password, host, origin, destination):
"""
Copy a local directory to a remote host. Trys 30 times, 30 seconds
"""
trys = 30
while True:
res = copy_to_host(user, password, host, origin, destination)
if tasks.get_return_code(res) == 0 or trys == 0:
return res
trys = trys - 1
time.sleep(1)