How to get the md5 checksum of files present in windows shared folder?

194 Views Asked by At

I'm using pysmb to connect to windows shared folder and calculate the md5 checksum of the files

I'm using hashlib for this purpose.

The code I have tried is as follows:

conn = SMBConnection(userName, password, config.clientMachineName, serverName, 
 use_ntlm_v2=True)
conn.connect(host, 139)
file_obj = tempfile.NamedTemporaryFile()
file_attributes, filesize = conn.retrieveFile(share_name, file_path, file_obj)

# calculate md5 hash
  md5_hash = hashlib.md5()
  while True:
      data = file_obj.read(1024)
      if not data:
          break
      md5_hash.update(data)
  print(file_path, md5_hash.hexdigest())

But it returns the same hexadecimal value for all files.

What can be the alternative solution?

0

There are 0 best solutions below