When transferring any file, MQTT Transmission requires two files to be present before it will transfer the target file. The first is the file itself. The second is a file that has the same name as the target file followed by a '.md5' extension. The contents of that file must contain the Message Digest Algorithm 5 (or MD5 sum) of the file. The MD5 sum can be calculated using command line utilities on most operating systems or through scripting in Ignition. Here are some examples: Linux | Code Block |
|---|
| ubuntu@linux-host:~$ md5sum myfile.bin
07180622a24ebf905cf5f770cd54197a myfile.bin
# In the above example, the md5 sum is: 07180622a24ebf905cf5f770cd54197a |
OSX | Code Block |
|---|
| user@osxhost:~$ md5 sample_file.txt
MD5 (sample_file.txt) = 85324ffbcc7d97c478adf53796aff787
# In the above example, the md5 sum is: 85324ffbcc7d97c478adf53796aff787 |
Windows | Code Block |
|---|
| Get-FileHash -Algorithm MD5 .\some_file.iso
Algorithm Hash Path
--------- ---- ----
MD5 80FD169D3FDADBC97E66C168F796B1BF C:\temp\some_file.iso
# In the above example, the md5 sum is: 80FD169D3FDADBC97E66C168F796B1BF |
Ignition Script | Code Block |
|---|
| import hashlib
# File to create md5 sum
file_name = "D:\MyFiles\test_file\test_file.txt"
# Open,close, read file and calculate MD5 on its contents
with open(file_name, 'rb') as file_to_check:
# read contents of the file
data = file_to_check.read()
# pipe contents of the file through
md5_returned = hashlib.md5(data).hexdigest()
# Save md5 sum file
f = open(file_name + ".md5", "w")
f.write(md5_returned)
f.close() |
|