Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较下载文件的MD5与Python中SFTP服务器上的文件_Python_Ssh_Sftp_Md5_Paramiko - Fatal编程技术网

比较下载文件的MD5与Python中SFTP服务器上的文件

比较下载文件的MD5与Python中SFTP服务器上的文件,python,ssh,sftp,md5,paramiko,Python,Ssh,Sftp,Md5,Paramiko,在这里,我试图列出我下载的所有MD5文件,并将它们与原始文件进行比较,看看它们是否是相同的文件。 我现在无法访问服务器来测试这段代码,但我真的很好奇它是否能工作。。。 是否有人有更好的解决方案,或者他们会改变什么 #!/usr/bin/python3 import paramiko import pysftp import os import sys print("Localpath eingeben: ") localpath = input() print("

在这里,我试图列出我下载的所有MD5文件,并将它们与原始文件进行比较,看看它们是否是相同的文件。 我现在无法访问服务器来测试这段代码,但我真的很好奇它是否能工作。。。 是否有人有更好的解决方案,或者他们会改变什么

#!/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()
我对Python很陌生,所以。。如果我犯了愚蠢的错误,请容忍我。
也许我必须先对它们进行排序?

如果您已经有了到同一服务器的本地Python ssh连接,那么启动外部控制台应用程序(
ssh
)在服务器上执行
md5sum
(并为每个文件打开一个新的连接)就太过分了

相反:

请注意,MD5已过时,请使用SHA-256(
sha256sum


尽管问题是整个校验和检查是否是一个过度的检查,请参阅:



强制性警告:不要使用
AutoAddPolicy
–这样做会失去保护。要获得正确的解决方案,请参阅。

如果您已经有到同一服务器的本机Python ssh连接,那么启动外部控制台应用程序(
ssh
)在服务器上执行
md5sum
(并为每个文件打开一个新连接),这是一种过分的做法

相反:

请注意,MD5已过时,请使用SHA-256(
sha256sum


尽管问题是整个校验和检查是否是一个过度的检查,请参阅:


强制性警告:不要使用
AutoAddPolicy
–这样做会失去保护。有关正确的解决方案,请参阅

stdin, stdout, stderr = c.exec_command('md5sum '+ files1)
checksum = stdout.read()