Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pexpect
- import getpass
- import sys
- def ssh(username,password,host,port,command,writeline):
- child = pexpect.spawn("ssh -p {} {}@{} '{}'".format(port,username,host,command))
- child.expect("password: ")
- child.sendline(password)
- if(writeline):
- print(child.read())
- def scp(username,password,host,port,file,dest):
- child = pexpect.spawn("scp -P {} {} {}@{}:{}".format(port,file,username,host,dest))
- child.expect("password: ")
- child.sendline(password)
- try:
- filename = sys.argv[1]
- print("=== sendhw remote commander ===")
- username = input("Username: ")
- password = getpass.getpass("Password: ")
- ssh(username,password,"some.host.net","22","mkdir ~/srakrnSRV",False)
- scp(username,password,"some.host.net","22",filename,"~/srakrnSRV")
- ssh(username,password,"some.host.net","22","cd srakrnSRV && sendhw {}".format(filename),True)
- except IndexError:
- print("No homework name specified.")
- b'rnbash: line 0: cd: srakrnSRV: No such file or directoryrn'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement