最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

python 读取其他服务器文件的方法

互联网 admin 1浏览 0评论

python 读取其他服务器文件的方法

使用Python语句,读取Linux远端服务器上的文件打印到控制台的代码实现:
下载包:paramiko

import paramiko
 
#服务器信息,主机名(IP地址)、端口号、用户名及密码
hostname = ""
port = 22
username = ""
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()

参考链接:
.html

python 读取其他服务器文件的方法

使用Python语句,读取Linux远端服务器上的文件打印到控制台的代码实现:
下载包:paramiko

import paramiko
 
#服务器信息,主机名(IP地址)、端口号、用户名及密码
hostname = ""
port = 22
username = ""
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()

参考链接:
.html

发布评论

评论列表 (0)

  1. 暂无评论