Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko, sys, hashlib, datetime
- hostname="127.0.0.1"
- password="rhrlehd"
- path = "/home/keikun"
- filename = "test.txt"
- source = path+"/"+filename
- dest = "test_dest.txt"
- username="keikun"
- port=22
- command = 'md5sum '+source
- trycount = 3
- def getHash(hostname, port, username, password):
- client = paramiko.SSHClient()
- client.load_system_host_keys()
- client.set_missing_host_key_policy(paramiko.WarningPolicy)
- client.connect(hostname, port=port, username=username, password=password)
- stdin, stdout, stderr = client.exec_command(command)
- return stdout.read()
- def getFile(hostname, port,username,password, srcFile, destFile):
- retVal = ""
- client = paramiko.Transport((hostname, port))
- try:
- client.connect(username=username, password=password)
- sftp = paramiko.SFTPClient.from_transport(client)
- sftp.get(source,destFile)
- finally:
- client.close()
- #f = open(destFile, "a")
- #f.write("TEST")
- #f.close()
- retVal = destFile
- return retVal
- def overWrite(source, destFile):
- pass
- hashkey = getHash(hostname, port, username, password).decode("utf-8").split(' ')
- if hashkey[0] :
- print(" source :" + hashkey[0])
- file = getFile(hostname, port, username, password , source, dest)
- destKey = hashlib.md5(open(file, "rb").read()).hexdigest()
- print(" destfile :" + destKey)
- if hashkey[0] == destKey:
- print(str(datetime.datetime.now())," : SUCCESS")
- else:
- print(str(datetime.datetime.now())," : FAIL")
- for i in (range(trycount)):
- print(str(datetime.datetime.now())," : RETRY - %d" % i)
- file = getFile(hostname, port, username, password , source, dest)
- destKey = hashlib.md5(open(file, "rb").read()).hexdigest()
- else :
- print ("fail")
Add Comment
Please, Sign In to add comment