使用Python語句,讀取Linux遠端服務器上的文件打印到控制臺的代碼實現:
下載包:paramiko
import paramiko#服務器信息,主機名(IP地址)、端口號、用戶名及密碼hostname = ""port = 22username = ""password = ""client = paramiko.SSHClient()client.set_missing_host_key_policy(paramiko.AutoAddPolicy())client.connect(hostname, port, username, password, compress=True)sftp_client = client.open_sftp()remote_file = sftp_client.open("/home/...txt")#文件路徑try: for line in remote_file: print(line)finally: remote_file.close()以上這篇python 讀取Linux服務器上的文件方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答