Here I am trying to list all the MD5's of the files I downloaded and compare them to the original to see if they are the same Files.
I can't access a server to test this code right now but I was really curious if it would work...
Does someone have a better solution or something they would change?
#!/usr/bin/python3
import paramiko
import pysftp
import os
import sys
print("Localpath eingeben: ")
localpath = input()
print("Remothpath eingeben: ")
remotepath = input()
k = paramiko.RSAKey.from_private_key_file("/home/abdulkarim/.ssh/id_rsa")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("connecting")
c.connect(hostname = "do-test", username = "abdulkarim", pkey = k)
print("connected")
sftp = c.open_sftp()
sftp.Connection.get_d(localpath, remotepath)
#sftp.get_d(localpath, remotepath)
def hashCheckDir(f,r):
files = []
# r=root, d=directories, f=files
for r, d, f in os.walk(localpath):
for file in f:
if '.txt' in file:
files.append(os.path.join(r, file))
files1 = []
# r=root, d=directories, f=files
for r, d, f in os.walk(remotepath):
for file in f:
if '.txt' in file:
files.append(os.path.join(r, file))
for i in range(2):
for x in files:
localsum = os.system('md5sum ' + files)
remotesum = os.system('ssh do-test md5sum ' + files1)
if localsum == remotesum:
print ("The lists are identical")
else :
print ("The lists are not identical")
hashCheckDir(localpath,remotepath)
c.close()
I am pretty new to Python so.. Bear with me if I did some stupid mistake.
Maybe I have to sort them first?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…