Commit 03a99eac by Marcin Bury

Windows support for ssh_interactive

parent 5d5d5c3d
...@@ -8,8 +8,6 @@ import random ...@@ -8,8 +8,6 @@ import random
import string import string
import socket import socket
import importlib import importlib
import termios
import tty
import select import select
import socket import socket
from functools import wraps from functools import wraps
...@@ -443,6 +441,16 @@ def boolify(value): ...@@ -443,6 +441,16 @@ def boolify(value):
def ssh_interactive(ssh): def ssh_interactive(ssh):
chan = ssh.invoke_shell() chan = ssh.invoke_shell()
try:
import termios
import tty
posix_shell(chan)
except:
windows_shell(chan)
def posix_shell(chan):
oldtty = termios.tcgetattr(sys.stdin) oldtty = termios.tcgetattr(sys.stdin)
try: try:
tty.setraw(sys.stdin.fileno()) tty.setraw(sys.stdin.fileno())
...@@ -456,12 +464,11 @@ def ssh_interactive(ssh): ...@@ -456,12 +464,11 @@ def ssh_interactive(ssh):
x = unicode(chan.recv(1024)) x = unicode(chan.recv(1024))
if(len(x) == 0): if(len(x) == 0):
sys.stdout.write('\r\nExiting...\r\n')
break break
sys.stdout.write(x) sys.stdout.write(x)
sys.stdout.flush() sys.stdout.flush()
except socket.timeout: except socket.timeout:
pass pass
...@@ -472,7 +479,31 @@ def ssh_interactive(ssh): ...@@ -472,7 +479,31 @@ def ssh_interactive(ssh):
break break
chan.send(x) chan.send(x)
finally: finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
return return
def windows_shell(chan):
def writeall(sock):
while True:
data = sock.recv(256)
if not data:
sys.stdout.flush()
return
sys.stdout.write(data)
sys.stdout.flush()
writer = threading.Thread(target=writeall, args=(chan,))
writer.start()
try:
while True:
d = sys.stdin.read(1)
if not d:
break
chan.send(d)
except:
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment