How to do os.walk()
but on another computer through SSH? The problem is that os.walk()
executes on a local machine and I want to ssh to another host, walk through a directory and generate MD5 hashes for every file within.
What I wrote so far looks like this (below code) but it doesn't work. Any help would be greatly appreciated.
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()