程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python operating Linux

編輯:Python
 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 .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved