python 读取Linux服务器上的文件方法
作者:qqqwww159
今天小编就为大家分享一篇python 读取Linux服务器上的文件方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
使用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()
以上这篇python 读取Linux服务器上的文件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- 如何把python项目部署到linux服务器
- Pycharm使用远程linux服务器conda/python环境在本地运行的方法(图解))
- Linux服务器上安装Python3的两种方式
- python和shell监控linux服务器的详细代码
- 详解Python下ftp上传文件linux服务器
- Linux下安装Python3和django并配置mysql作为django默认服务器方法
- Linux服务器网卡流量查看方法 shell和Python各一枚
- Linux下将Python的Django项目部署到Apache服务器
- python下paramiko模块实现ssh连接登录Linux服务器
- Python 代替 xftp 从 Linux 服务器下载文件的操作方法
