The main use of paramiko modular #python operation linux # There are several points to pay attention to during operation , Such as stdout.readlines() Such a call is best reassigned to another variable , The result of directly using this as a variable will not report an error , But the result is wrong import paramiko import re def get_connect(): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('ip',port,'user','password') sftp = ssh.open_sftp() stdin,stdout,stderr = ssh.exec_command('cd /file_store/qs;ls;') file = stdout.readlines() for i in range(len(file)): file_name = str(file[i]).replace('\n','') print(file_name) sftp.get('/file_store/qs/%s'%file_name,'./%s'%file_name,None) print('success') if __name__ == '__main__': get_connect()
The main structure of this module can be divided into the following points :
One 、 Connect
Two 、 Carry out orders
3、 ... and 、 Upload or download files
In fact, we are liunx That's all I did in the , The summary framework is relatively large , There are still many things that can be refined .
For example, connections can be divided into win->linux or linux->linux. There are two different types , Connection configuration requirements are different . So the parameters you need to input are different . Currently only unlocked win->Linux.linux->linux The public key needs to be configured , The method of account and password is under test .