0

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?

Gary
  • 31
  • 1
  • 6
  • 1
    As far as I can see, this code calculates the hash of `file_obj`, which is always a new (and thus empty) temporary file... – John Gordon Feb 17 '23 at 02:29
  • I think you should read the whole file and create a hash. ( checksum) you are doing something else. – Amin S Feb 17 '23 at 02:31
  • Where is the code that lists the contents of the shared folder, and reads individual files from the folder? – John Gordon Feb 17 '23 at 02:32

0 Answers0