且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Python 使用 SSH 从服务器读取文件

更新时间:2023-12-05 14:34:46

Paramiko 的 SFTPClient 允许你获取一个类似文件的对象,以 Pythonic 的方式从远程文件中读取数据.

Paramiko's SFTPClient class allows you to get a file-like object to read data from a remote file in a Pythonic way.

假设你有一个开放的SSHClient:

sftp_client = ssh_client.open_sftp()
remote_file = sftp_client.open('remote_filename')
try:
    for line in remote_file:
        # process line
finally:
    remote_file.close()