标签:slist usr int stc connect sdn shell命令 linu web
def connect(host,username,password): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: ssh.connect(host,username=username,password=password,allow_agent=True) return ssh except: return None
def exec_commands(conn,cmd): stdin,stdout,stderr = conn.exec_command(cmd) results=stdout.read()+stderr.read() print(results) return results
def ftpssh(frompath,topath,method="get"): t = paramiko.Transport(远程机器IP) t.connect(username= 远程机器登录用户名, password = 远程机器登录密码) sftp = paramiko.SFTPClient.from_transport(t) if method == "get":#将远程文件copy到本地 sftp.get(frompath, topath) elif method == "put":#将本地文件copy到远程机器上 sftp.put(frompath, topath) t.close()
cmd="source ~/.bash_profile;/usr/local/bin/python3 ./test.py >> ./log.txt 2>&1" exec_commands(cmd) ftpssh(WebmanageConfig.uitestpath + "/testsuit/temptestcaseslist.txt", "./temptestcaseslist.txt")
标签:slist usr int stc connect sdn shell命令 linu web
原文地址:http://www.cnblogs.com/meitian/p/7019643.html