Advertisement
Guest User

Untitled

a guest
Oct 8th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import pexpect
  2. import getpass
  3. import sys
  4.  
  5. def ssh(username,password,host,port,command,writeline):
  6. child = pexpect.spawn("ssh -p {} {}@{} '{}'".format(port,username,host,command))
  7. child.expect("password: ")
  8. child.sendline(password)
  9. if(writeline):
  10. print(child.read())
  11.  
  12. def scp(username,password,host,port,file,dest):
  13. child = pexpect.spawn("scp -P {} {} {}@{}:{}".format(port,file,username,host,dest))
  14. child.expect("password: ")
  15. child.sendline(password)
  16.  
  17. try:
  18. filename = sys.argv[1]
  19. print("=== sendhw remote commander ===")
  20. username = input("Username: ")
  21. password = getpass.getpass("Password: ")
  22. ssh(username,password,"some.host.net","22","mkdir ~/srakrnSRV",False)
  23. scp(username,password,"some.host.net","22",filename,"~/srakrnSRV")
  24. ssh(username,password,"some.host.net","22","cd srakrnSRV && sendhw {}".format(filename),True)
  25.  
  26. except IndexError:
  27. print("No homework name specified.")
  28.  
  29. b'rnbash: line 0: cd: srakrnSRV: No such file or directoryrn'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement