-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathChannelSSH.py
More file actions
27 lines (23 loc) · 743 Bytes
/
ChannelSSH.py
File metadata and controls
27 lines (23 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from time import sleep
def receiveFromChannel(channel):
lengdatawait = -1
data = ""
while channel.get_transport().is_active():
if channel.recv_ready():
if lengdatawait < 0:
a = channel.recv(4096)
a= a.split('\0',1)
lengdatawait = int(a[0])
data = a[1]
if lengdatawait == len(data):
return data
data += channel.recv(lengdatawait-len(data))
if lengdatawait == len(data):
return data
else:
sleep(0.2)
def sendToChannel(data,channel):
datatosend = str(len(data)) + '\0' + data
channel.sendall(datatosend)
def closeChannel(channel):
channel.close()