Using Paramiko in Python for remote operation requires the installation of the Paramiko module.
# VI pssh.py
#!/usr/bin/python#Coding=utf-8" "Created on APR, 2016@author:root" "ImportParamikoclassPSSH ():def __init__(Self,ip,sort,username,password): Self.ip=IP self.sort=Sort Self.username=username Self.passwrod=PassworddefExec_cmd (self,cmd): SSH=Paramiko. Sshclient () Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())#Ssh.connect (hostname, port, username, password, pkey, key_filename, timeout, allow_agent, Look_for_keys, compress, Sock)Ssh.connect (self.ip,self.sort,self.username,self.passwrod) Stdin,stdout,stderr=Ssh.exec_command (cmd)Printstdout.readlines () ssh.close ( )defupfile (self,localpath,remotepath):" " " "T=Paramiko. Transport ((Self.ip,self.sort)) T.connect (username= self.username,password=Self.passwrod) sftp=Paramiko. Sftpclient.from_transport (t) sftp.put (Localpath,remotepath) t.close ()defDownfile (self,remotepath,localpath):" " " "T=Paramiko. Transport ((Self.ip,self.sort)) T.connect (username= self.username,password=Self.passwrod) sftp=Paramiko. Sftpclient.from_transport (t) sftp.get (Remotepath,localpath) t.close ()if __name__=='__main__': Pssh= PSSH ("192.168.1.77", 22,"Oracle","Oracle"); #pssh.exec_cmd ("Cat/tmp/a.txt") #pssh.upfile ("/tmp/1.txt", "/tmp/1.txt")Pssh.downfile ("/tmp/a.txt","/tmp/a.txt") Print '------Success!-----'
Test download function
# # #------Success!-----#-rw-r--r--. 1 root root 4 Apr 10:16 a.txt
Python remote execution command, upload, download example