Python read remote file from linux server

自动化要读取Server上的文件来判断Json的正确与否,还是通过Paramiko实现,这里一个简单例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if __name__ == "__main__":
hostname = 'xxx'
port = 22
username = 'xxx'
password = 'xxx'

s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname, port, username, password)

sftp_client = s.open_sftp()
remote_file = sftp_client.open('/tmp/file')
try:
for line in remote_file:
print line
finally:
remote_file.close()
s.close()
唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!