import paramiko import time def client(): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(hostname="192.168.56.100",port=22,username="huawei",password="Admin@123") cmd = client.invoke_shell() cmd.send("screen-length 0 temporary\n") time.sleep(1) cmd.send("sys imm\n") time.sleep(1) cmd.send("interface g1/0/0\n") time.sleep(1) cmd.send("undo shutdown\n") time.sleep(1) cmd.send("undo portswitch\n") time.sleep(1) cmd.send("int lo0\n") time.sleep(1) cmd.send("ip add 2.2.2.2 32\n") time.sleep(1) print(cmd.recv(65535).decode("utf-8")) cmd.close() def read_txt(): client2 = paramiko.SSHClient() client2.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client2.connect(hostname="192.168.56.100",port=22,username="huawei",password="Admin@123") cmd2 = client2.invoke_shell() f = open("cmd.txt","r") mes = f.readlines() for line in mes: cmd2.send(line) time.sleep(1) print(cmd2.recv(65535).decode("utf-8")) cmd2.close() read_txt() def down(): trs = paramiko.Transport(("192.168.56.100",22)) trs.connect(username="huawei",password="Admin@123") sftp = paramiko.SFTPClient.from_transport(trs) remote = "device.sys" local = "new.sys" sftp.get(remote,local) trs.close() down() def up(): trs = paramiko.Transport(("192.168.56.100",22)) trs.connect(username="huawei",password="Admin@123") sftp = paramiko.SFTPClient.from_transport(trs) remote = "new.txt" local = "cmd.txt" sftp.put(local,remote) trs.close() up()