1

With Python, I need to read a file into a script similar to open(file,"rb"). However, the file is on a server that I can access through SSH. Any suggestions on how I can easily do this? I am trying to avoid paramiko and am using pexpect to log into the SSH server, so a method using pexpect would be ideal.

Thanks, Eric

4

2 回答 2

1

您可以使用sshfs将远程文件系统挂载到本地,然后您可以像普通文件一样使用。该fuse模块是sshfs.

于 2011-12-08T01:48:14.500 回答
0

如果它是一个短文件,您可以使用 subprocess.Popen 获取 ssh 命令的输出

ssh root@ip_address_of_the_server 'cat /path/to/your/file'

注意:应配置使用密钥的无密码设置才能使其正常工作。

于 2011-12-08T01:52:51.890 回答