I found the source of the error, so I developed a workaround strategy that works quite well.
By changing the strategy to ensure the sends, I noticed that the first chunk was not being received. I believe this is a synchronization issue caused by an initialization latency in the TCP connection.
So, for the first chunk only, I introduced a 0.01-second delay, and now no files are corrupted.
To ensure proper reception, I used a hash comparison via the hashlib
library.