How do I get the checksum of the remote server files in paramiko?

Asked 2 years ago, Updated 2 years ago, 127 views

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.

python python3 ssh openssh

2022-09-30 20:13

1 Answers

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.


2022-09-30 20:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.