ftp获取文件的md5

import ftplib
import hashlib

def get_ftp_md5(ftp, remote_path):
    m = hashlib.md5()
    ftp.retrbinary('RETR %s' % file_remote_path, m.update)
    return m.hexdigest()

ftp.voidcmd("XSHA1 " + filename)

参加:MD5 value for file in a remote FTP server using Python ftplib

本地文件获取 md5

hashlib.md5(open('filename.exe','rb').read()).hexdigest()

字符串获取 md5

Hashlib. Md 5 ("example string"). Hexdigest ()

参加:How do I calculate the MD5 checksum of a file in Python?