Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- class SSH():
- PLINK = "win32\plink.exe"
- PSCP = "win32\pscp.exe"
- def __init__(self, host, username, password):
- self.host = host
- self.username = username
- self.password = password
- if os.name != "nt":
- self.SSHPASS = "sshpass -p" + password
- def upload(self, src, dst):
- if os.name == "nt":
- cmd = self.PSCP + " -scp -pw " + self.password + " " + src + " " + self.username + "@" + self.host + ":" + dst
- else:
- cmd = self.SSHPASS + " scp -o StrictHostKeyChecking=no " + src + " " + self.username + "@" + self.host + ":" + dst
- print(cmd)
- return os.system(cmd) == 0
- def exec(self, command):
- if os.name == "nt":
- cmd = self.PLINK + " -ssh -pw " + self.password + " " + self.username + "@" + self.host + " " + command
- else:
- cmd = self.SSHPASS + " ssh -o StrictHostKeyChecking=no " + self.username + "@" + self.host + " " + command
- print(cmd)
- return os.system(cmd) == 0
- if __name__ == "__main__":
- s = SSH(host="localhost", username="root", password="1234")
- s.upload(src="firmware.v1.0.bin", dst="/tmp/firmware.bin")
- s.exec("mtd -r write /tmp/firmware.bin Kernel")
Add Comment
Please, Sign In to add comment