【发布时间】:2019-11-02 09:59:42
【问题描述】:
如何通过 SSH 在另一台计算机上执行os.walk()?问题是 os.walk() 在本地机器上执行,我想 ssh 到另一台主机,遍历目录并为其中的每个文件生成 MD5 哈希。
到目前为止我写的看起来像这样(下面的代码),但它不起作用。任何帮助将不胜感激。
try:
hash_array = []
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('sunbeam', port=22, username='xxxx', password='filmlight')
spinner.start()
for root, dirs, files in os.walk(_path):
for file in files:
file_path = os.path.join(os.path.abspath(root), file)
# generate hash code for file
hash_array.append(genMD5hash(file_path))
file_nb += 1
spinner.stop()
spinner.ok('Finished.')
return hash_array
except Exception as e:
print(e)
return None
finally:
ssh.close()
【问题讨论】: