In the process of downloading a file from the Windows local environment to the server using STFP, I would like to check if the file on the server is the same as the downloaded file.
Therefore, I would like to check it, but I am not sure how to get the hash value of the remote server file.
Thank you for your cooperation.
Assume that the server is a UNIX OS, but you might want to run a command on the server that calculates the checksum such as md5sum and sha256sum to receive the resulting text.
import paramiko
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("hoge.example.com", username="test", password="testpass")
stdin, stdout, stderr = ssh.exec_command('md5sum.bashrc')
for line instdout:
print(line.strip('\n')
ssh.close();
If you want to verify a successful file transfer, you can calculate the checksum locally using a similar algorithm and compare it.
Try it.
© 2024 OneMinuteCode. All rights reserved.