I am building an application where it SSHs to Cisco devices to collect output of show
commands. I am using paramiko module in python to get this done.
While comparing the command output with that of plink
, got to know that the output from paramiko is truncated. Tried with unbuffering and increased buffer size and it didn't help. Later, just tried with window_size
parameter and it seems to work.
Below is my code:
import paramiko
sshclient = None
try:
sshclient = paramiko.SSHClient()
sshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sshclient.connect('mydevice', username='admin', password='admin12345')
chan = sshclient.get_transport().open_session(window_size=500000)
chan.settimeout(10800)
chan.exec_command('show tech-support fcip')
value = chan.recv(1024)
while value:
print(value)
value = chan.recv(1024)
finally:
if sshclient:
sshclient.close()
As per paramiko document for Transport, default_window_size=2097152
; 1597152 lesser than the default_value.
Also the partial log output with default_window_size=2097152
is:
Authentication (password) successful!
[chan 0] Max packet in: 32768 bytes
[chan 0] Max packet out: 32768 bytes
Secsh channel 0 opened.
[chan 0] Sesch channel 0 request ok
EOF in transport thread
Where as with window_size=500000
is:
Authentication (password) successful!
[chan 0] Max packet in: 32768 bytes
[chan 0] Max packet out: 32768 bytes
Secsh channel 0 opened.
[chan 0] Sesch channel 0 request ok
[chan 0] EOF received (0)
EOF in transport thread
Here it looks like, when the window_size is default value, the channel is being closed even before the termination signal from the server.
Experts, please advise me the consequences of reduced window_size
in SSH and how will it affect my application?