Subject: Re: SSH client is not reading full data if executed command generates big output

Re: SSH client is not reading full data if executed command generates big output

From: Peter Stuge <peter_at_stuge.se>
Date: Sat, 27 Oct 2018 23:21:52 +0000

Your attached example requests a VT100 pseudo-terminal (pty) from the
server, but does not include any terminal emulation whatsoever. That
will never work reliably in the general case.

PuTTY includes significant terminal emulation code. Linux/Unix systems
always have a terminal emulator. Windows never does.

Subrata Dasgupta wrote:
> But when output of the remotely executed program is very big then
> the client is not able to read all the data. Seems server is sending
> the partial data and then the command prompt.

In other words: Without terminal emulation, communication is unreliable.

> But if I connect the same server using PUTTY and execute the same
> command then PUTTY terminal is showing &quot;more&quot; at the end
> of terminal and wait for my &quot;return&quot; key press.

In other words: With terminal emulation, communication is reliable.

> My objective is to read all the output of the command without blocking
> on &quot;more&quot; ( means &quot;return&quot; key press).
> How can I achieve this ?

It depends on the capabilities of your server system, but quite
likely you will need to implement some if not full terminal emulation
and then you may have to make your program recognize the "more" prompt,
and then simulate a human pressing "return", while also filtering
that out of the data stream that you want to scrape.

If you're lucky then the server also supports a non-interactive terminal
type, where you can scrape all output without interaction. That's all
completely out of scope of the SSH protocol and thus libssh2, it is
exclusively a property of your particular server. You can try using
"raw", "ascii" and maybe some others instead of "vt100" in the example -
whatever your research on that topic finds may be worth a try.

I will recommend to search for an API offered by the server product
to do what you want instead of trying to automate around the
interactive interface.

Good luck.

//Peter
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2018-10-28