Comparing Md5 Of Downloaded Files Against Files On An Sftp Server In Python
Here I am trying to list all the MD5's of the files I downloaded and compare them to the original to see if they are the same Files. I can't access a server to test this code right
Solution 1:
It's an overkill to launch an external console application (ssh
) to execute md5sum
on the server (and open a new connection for each and every file on top of that), if you already have a native Python SSH connection to the same server.
Instead use SSHClient.exec_command
:
stdin, stdout, stderr = c.exec_command('md5sum '+ files1)
checksum = stdout.read()
Note that MD5 is obsolete, use SHA-256 (sha256sum
).
Though question is whether the whole checksum check isn't an overkill, see: How to perform checksums during a SFTP file transfer for data integrity?
Obligatory warning: Do not use AutoAddPolicy
– You are losing a protection against MITM attacks by doing so. For a correct solution, see Paramiko "Unknown Server".
Post a Comment for "Comparing Md5 Of Downloaded Files Against Files On An Sftp Server In Python"