0 votes
by (150 points)

We are using the Terminal scripting object (r6.11) to connect to Windows 2019 OpenSSH (8.6)

When we send the "type" command to list a text file, we get a random repetition of the line content from the ReadUntil(events) within the same line (ie with one line terminator)

Some do not repeat; when they do it's the complete line from a seemingly random start point that we get appended to the end of the rest of the line following padding to Columns.

No lines are actually longer than 80 characters
When we changed the Columns to 120 the repetition started at 120+1

We have tried changing the ImplicitCarriageReturn and the AutoWrapMode to .Dos and .On

This does not happen with the same code using the "cat" command on our linux servers.

Is there some other option we have missed that we need to set in order to deal with Windows?

Thank you.

1 Answer

0 votes
by (144k points)
selected by
 
Best answer

The Scripting class uses a shell session with a pseudo-terminal, which means that SSH servers could use various ANSI escape sequences that are not perceived by a user when there is a human operating the terminal, but that could really confuse our scripting interpreter.

For example, a terminal could choose to show a "Hello world" text, but do it like this:

  1. Write "H".
  2. Move cursor X position 5 characters to the right.
  3. Write "w".
  4. Move cursor X position 6 characters to the left.
  5. Write "e".
  6. Move cursor X position 5 characters to the right.
  7. Write "o".
  8. ...

A human would not notice this, but the scripting API's might parse the response as "Hweolrllod" instead of "Hello world".

This was an extreme example, but we have observed somewhat similar kinds of behavior with Windows SSH servers, in particular related to the way they structured the output of the prompt. So it would not be surprising if Windows OpenSSH exhibited similar unfortunate behavior. It seems that most Rebex Terminal users use it for interfacing to Unix-like systems, which usually behave in a predictable and straightforward way. We will look into this and see whether we can do anything about it.

In the meantime, consider using the older Shell API that doesn't use shell with a pseudo-terminal:

var ssh = new Ssh();
ssh.Connect(...);
ssh.Login(...);

Shell shell = ssh.StartCommand(@"type c:\folder\myfile.txt");
string response = shell.ReadAll();
...