-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.py
More file actions
29 lines (20 loc) · 804 Bytes
/
connection.py
File metadata and controls
29 lines (20 loc) · 804 Bytes
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
from paramiko import *
from os import *
def send_file(ssh_client, directory, local_audits_dir, os_):
ftp_client = ssh_client.open_sftp()
ftp_client.put(local_audits_dir + "")
ftp_client.close()
def set_audit(hostname):
audits_dir = "home/" + hostname + "/audits"
dir_exists = os.path.exists(audits_dir)
if not dir_exists:
mkdir(audits_dir)
else:
os.chdir(audits_dir)
def establish_connection(hostname, login, password):
ssh_client = SSHClient()
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(AutoAddPolicy())
ssh_client.connect(hostname=hostname, port=22, username=login, password=password)
if __name__ == "__main__":
establish_connection('ubuntutest', 'ubuntutest', 'qazwsx')