0 votes
by (120 points)

By default port ,Commands are executing for Telnet connection but for Custom port for same Telnet Connection is getting timedout ,below is the code where timeout is happening,Please help

telnetClient = new Telnet(serverAddress,28);//Custom port setting
telnetClient.Timeout = (scriptSessionTimeout > scriptTaskTimeout) ? scriptSessionTimeout : scriptTaskTimeout + 10000; // Session timeout must be higher that script task timeout!!
if (!string.IsNullOrEmpty(rebexLogFileName))
{
telnetClient.LogWriter = new Rebex.FileLogWriter(rebexLogFileName, (Rebex.LogLevel)Enum.Parse(typeof(Rebex.LogLevel), rebexLogLevel, true));
}

            virtualTerminal = new VirtualTerminal(80, 50);
            virtualTerminal.Scripting.HoldReceivedData = true;
            virtualTerminal.Scripting.Timeout = scriptTaskTimeout;
            virtualTerminal.Options.LocalEcho = false;
            virtualTerminal.Disconnected += new EventHandler(OnDisconnectedHandler);
            //virtualTerminal.DataReceived += new DataReceivedEventHandler(OnVTermDataReceivedHandler);
            virtualTerminal.DataReceived +=  OnVTermDataReceivedHandler;

            virtualTerminal.Bind(telnetClient);//Connection establishing

//while sending the command to the device from below code
scriptMatchResult = virtualTerminal.Scripting.WaitFor(ScriptEvent.Timeout, ScriptEvent.Closed, ScriptEvent.FromRegex(prompt));//Here timeout happening

1 Answer

0 votes
by (73.5k points)

Can you please create the communication log with rebexLogLevel set to Verbose?
This will capture the raw data received from the server.

I think that the server sends prompt you are not expecting by the ScriptEvent.FromRegex(prompt).

Normally, the server asks for username and password. If you are waiting for prompt just after the connection, it will time out.
Another possibility is that you are expecting prompt like "user@machine$" but the prompt sent by the server is e.g. "machine#".

The Verbose communication log will show us what is going on.

by (120 points)
Hi Lukas,
Thanks for  the response.We are using COPSSH client and customPort number menstioned in the COPSSH.
I have enabled the Rebex logging and able to see the logs.
Here is the logs i can see for the above timeout issue,

2022-11-24 12:19:49.994 INFO Telnet(2)[3] Info: Assembly: Rebex.Telnet R6.8 for .NET 4.0-4.8 (Trial)
2022-11-24 12:19:49.994 INFO Telnet(2)[3] Info: Platform: Windows 10.0.14393 64-bit; CLR: 4.0.30319.42000
2022-11-24 12:19:49.994 DEBUG Telnet(2)[3] Info: Culture: en; Windows-1252
2022-11-24 12:19:49.994 DEBUG Telnet(2)[3] Proxy: Connecting to **.**.*.**:1990 (no proxy).
2022-11-24 12:19:49.995 DEBUG Telnet(2)[3] Proxy: Connection established.
2022-11-24 12:19:49.995 DEBUG Telnet(2)[3] Info: Sending DO request option for: Echo (0x01).
2022-11-24 12:19:49.995 DEBUG Telnet(2)[3] Info: Sent 3 byte(s) of data.
2022-11-24 12:19:49.995 VERBOSE Telnet(2)[3] Info: Sent data:
 0000 |FF-FD-01                                       | ...
2022-11-24 12:19:49.996 DEBUG VirtualTerminal(0)[3] Scripting: WaitFor((timeout: 60000 | (closed | received regex: '[Ll]ogin:'))) [Timeout=60000]
2022-11-24 12:19:49.996 VERBOSE VirtualTerminal(0)[3] Scripting: WaitFor: polling data for max 60000 ms.
2022-11-24 12:19:50.061 DEBUG Telnet(2)[3] Info: Received 21 byte(s) of data.
2022-11-24 12:19:50.061 VERBOSE Telnet(2)[3] Info: Received data:
 0000 |53-53-48-2D-32-2E-30-2D 4F-70-65-6E-53-53-48-5F| SSH-2.0-OpenSSH_
 0010 |36-2E-37-0D-0A                                 | 6.7..
2022-11-24 12:19:50.061 VERBOSE VirtualTerminal(0)[3] Scripting: WaitFor: data received, reset last data received time stamp.
2022-11-24 12:19:50.061 VERBOSE VirtualTerminal(0)[3] Scripting: WaitFor: processing received data.
2022-11-24 12:19:50.062 VERBOSE VirtualTerminal(0)[3] Scripting: WaitFor: polling data for max 60000 ms.
2022-11-24 12:20:50.070 VERBOSE VirtualTerminal(0)[3] Scripting: WaitFor: no data received in 60000 ms.
2022-11-24 12:20:50.070 VERBOSE VirtualTerminal(0)[3] Scripting: WaitFor: last data received 60015 ms ago.
2022-11-24 12:20:50.070 VERBOSE VirtualTerminal(0)[3] Scripting: WaitFor: ScriptEvent.Timeout successfully evaluated.
2022-11-24 12:20:50.070 DEBUG VirtualTerminal(0)[3] Scripting: WaitFor finished with Success.
  Matched script events: timeout: 60000, (timeout: 60000 | (closed | received regex: '[Ll]ogin:'))
by (73.5k points)
Thank you for the log. It is clear now. You are connecting to an SSH server, but you are using Telnet component, which does not handle SSH communication. Please, use the Ssh class instead.

You can use it the same way, as you were using the telnetClient instance:
  virtualTerminal.Bind(sshClient);

More info at https://www.rebex.net/terminal-emulation.net/features/terminal-emulation.aspx#virtual-terminal
by (120 points)
Added below code
 Ssh sshClient = new Ssh();
  sshClient.Connect(serverAddress, CustomPortNumber);
 virtualTerminal = new VirtualTerminal(80, 50);
                virtualTerminal.Scripting.HoldReceivedData = true;
                virtualTerminal.Scripting.Timeout = scriptTaskTimeout;
                virtualTerminal.Options.LocalEcho = false;
                virtualTerminal.Disconnected += new EventHandler(OnDisconnectedHandler);
               // virtualTerminal.DataReceived += new DataReceivedEventHandler(OnVTermDataReceivedHandler);
                virtualTerminal.DataReceived +=  OnVTermDataReceivedHandler;

               // virtualTerminal.Bind(telnetClient);
                virtualTerminal.Bind(sshClient);

Below error it was writing in rebex log,

Telnet: Connection attempt Failed: Rebex SFTP/SSH does not support FTP or FTP/SSL protocol. Use Rebex FTP/SSL component instead.
2022-11-24 14:40:35,041 [5] ERROR - Exception info at level 0:
Exception type: SshException
Exception Message: Rebex SFTP/SSH does not support FTP or FTP/SSL protocol. Use Rebex FTP/SSL component instead.
by (120 points)
Sorry we are using CesarFTP client
by (73.5k points)
edited by
Please ensure you are connecting to the same IP and port 1990.
It can be seen in the previous log:

2022-11-24 12:19:49.994 DEBUG Telnet(2)[3] Proxy: Connecting to **.**.*.**:1990 (no proxy).
...
2022-11-24 12:19:50.061 VERBOSE Telnet(2)[3] Info: Received data:
 0000 |53-53-48-2D-32-2E-30-2D 4F-70-65-6E-53-53-48-5F| SSH-2.0-OpenSSH_

There is an SSH server at this IP and port 1990. However, it seems that you are now connecting to an FTP server.
by (120 points)
Application Log
 ------------------------------------
Begin ScriptMangerTelnet->ExecuteCommands()
2022-11-24 15:59:49,579 [9] INFO  - Attempting connection to host
2022-11-24 15:59:49,603 [9] INFO  - EventDeviceId 133061Server Address *.*.*.* Port Number1990
2022-11-24 15:59:49,771 [9] INFO  - Connection successfully established for host: *.*.*.* port:1990
2022-11-24 15:59:49,771 [9] INFO  - Attempting to login using Profile Login/Password credentials. Using Login: administrator
2022-11-24 15:59:49,775 [9] ERROR - TelnetScriptTimeout Prompt [Ll]ogin:
2022-11-24 15:59:49,859 [9] INFO  - OnVTermDataReceivedHandler called: *.*.*.* Telnet Data Recieved 220 CesarFTP 0.99e Server Welcome !

2022-11-24 16:00:49,861 [9] ERROR - Telnet Data Received: 220 CesarFTP 0.99e Server Welcome !

2022-11-24 16:00:49,861 [9] ERROR - Download Event Failed for system: Telnet Task timed out without a response from the host device ****
2022-11-24 16:00:49,861 [9] ERROR - Task Timed Out waiting for command prompt: [Ll]ogin: after waiting: 60000 ms
2022-11-24 16:00:49,867 [9] INFO  - Telnet Session disconnected from host: *.*.*.*
2022-11-24 16:00:50,262 [9] INFO  - --- End Telnet PreCommand Sequence ---


Rebex log
----------------
2022-11-24 16:13:46.269 INFO Telnet(2)[9] Info: Assembly: Rebex.Telnet R6.8 for .NET 4.0-4.8 (Trial)
2022-11-24 16:13:46.269 INFO Telnet(2)[9] Info: Platform: Windows 10.0.14393 64-bit; CLR: 4.0.30319.42000
2022-11-24 16:13:46.269 DEBUG Telnet(2)[9] Info: Culture: en; Windows-1252
2022-11-24 16:13:46.269 DEBUG Telnet(2)[9] Proxy: Connecting to *.*.*.* :1990 (no proxy).
2022-11-24 16:13:46.270 DEBUG Telnet(2)[9] Proxy: Connection established.
2022-11-24 16:13:46.270 DEBUG Telnet(2)[9] Info: Sending DO request option for: Echo (0x01).
2022-11-24 16:13:46.270 DEBUG Telnet(2)[9] Info: Sent 3 byte(s) of data.
2022-11-24 16:13:46.270 VERBOSE Telnet(2)[9] Info: Sent data:
 0000 |FF-FD-01                                       | ...
2022-11-24 16:13:46.270 DEBUG VirtualTerminal(0)[9] Scripting: WaitFor((timeout: 60000 | (closed | received regex: '[Ll]ogin:'))) [Timeout=60000]
2022-11-24 16:13:46.270 VERBOSE VirtualTerminal(0)[9] Scripting: WaitFor: polling data for max 60000 ms.
2022-11-24 16:13:46.270 DEBUG Telnet(2)[9] Info: Received 37 byte(s) of data.
2022-11-24 16:13:46.270 VERBOSE Telnet(2)[9] Info: Received data:
 0000 |32-32-30-20-43-65-73-61 72-46-54-50-20-30-2E-39| 220 CesarFTP 0.9
 0010 |39-65-20-53-65-72-76-65 72-20-57-65-6C-63-6F-6D| 9e Server Welcom
 0020 |65-20-21-0D-0A                                 | e !..
2022-11-24 16:13:46.270 VERBOSE VirtualTerminal(0)[9] Scripting: WaitFor: data received, reset last data received time stamp.
2022-11-24 16:13:46.270 VERBOSE VirtualTerminal(0)[9] Scripting: WaitFor: processing received data.
2022-11-24 16:13:46.271 VERBOSE VirtualTerminal(0)[9] Scripting: WaitFor: polling data for max 60000 ms.
2022-11-24 16:14:46.265 VERBOSE VirtualTerminal(0)[9] Scripting: WaitFor: no data received in 60000 ms.
2022-11-24 16:14:46.265 VERBOSE VirtualTerminal(0)[9] Scripting: WaitFor: last data received 60000 ms ago.
2022-11-24 16:14:46.265 VERBOSE VirtualTerminal(0)[9] Scripting: WaitFor: ScriptEvent.Timeout successfully evaluated.
2022-11-24 16:14:46.265 DEBUG VirtualTerminal(0)[9] Scripting: WaitFor finished with Success.
  Matched script events: timeout: 60000, (timeout: 60000 | (closed | received regex: '[Ll]ogin:'))
by (73.5k points)
You are now connecting to a FTP server using telnet. It is possible to script FTP protocol using Telnet, but it is a little more tricky. Moreover, you will not be able to transfer files nor list directories, because it requires to establish new TCP connection for each transfer.

We have Ftp class for accessing FTP servers. Please, use rather Ftp component: https://www.rebex.net/ftp-ssl.net/features/connecting.aspx#connect

What are you trying to achieve by using Telnet for FTP server?
by (120 points)
I am trying to run commands with Custom port for Telnet
by (73.5k points)
There is no speciality in using custom port.
A TCP connection is established for given address/port, then the Telnet handler processes the communication over the given TCP connection (always the same way, regardless the initial address/port).

However, please note that Telnet protocol has some specifics. I mean Telnet Options Negotiation. If you are not connecting to a Telnet server, you should not send any Telnet Options from client.
At the moment, the only Telnet Option which is send just after the connection is established is ECHO. To disable sending ECHO Telnet Option, please set:

  virtualTerminal.Options.LocalEcho = true

You must set it before you bind the Telnet object to the virtualTerminal instance.

With this, you will probably achieve your desired result = you can script plaintext communication with the remote server.
by (120 points)
This is Rebex log:
2022-11-30 17:14:05.257 INFO Telnet(1)[18] Info: Connecting to **.**.**.**:1990 using Telnet.
2022-11-30 17:14:05.257 INFO Telnet(1)[18] Info: Assembly: Rebex.Telnet R6.8 for .NET 4.0-4.8 (Trial)
2022-11-30 17:14:05.257 INFO Telnet(1)[18] Info: Platform: Windows 10.0.14393 64-bit; CLR: 4.0.30319.42000
2022-11-30 17:14:05.257 DEBUG Telnet(1)[18] Info: Culture: en; Windows-1252
2022-11-30 17:14:05.273 DEBUG Telnet(1)[18] Proxy: Connecting to **.**.**.**:1990 (no proxy).
2022-11-30 17:14:05.284 DEBUG Telnet(1)[18] Proxy: Connection established.
2022-11-30 17:14:05.289 DEBUG Telnet(1)[18] Info: Sending DO request option for: Echo (0x01).
2022-11-30 17:14:05.293 DEBUG Telnet(1)[18] Info: Sent 3 byte(s) of data.
2022-11-30 17:14:05.297 VERBOSE Telnet(1)[18] Info: Sent data:
 0000 |FF-FD-01                                       | ...
2022-11-30 17:14:05.317 DEBUG VirtualTerminal(0)[18] Scripting: WaitFor((timeout: 60000 | (closed | received regex: '[Ll]ogin:'))) [Timeout=60000]
2022-11-30 17:14:05.330 VERBOSE VirtualTerminal(0)[18] Scripting: WaitFor: polling data for max 60000 ms.
2022-11-30 17:14:05.339 DEBUG Telnet(1)[18] Info: Received 21 byte(s) of data.
2022-11-30 17:14:05.339 VERBOSE Telnet(1)[18] Info: Received data:
 0000 |53-53-48-2D-32-2E-30-2D 4F-70-65-6E-53-53-48-5F| SSH-2.0-OpenSSH_
 0010 |36-2E-37-0D-0A                                 | 6.7..
2022-11-30 17:14:05.345 VERBOSE VirtualTerminal(0)[18] Scripting: WaitFor: data received, reset last data received time stamp.
2022-11-30 17:14:05.345 VERBOSE VirtualTerminal(0)[18] Scripting: WaitFor: processing received data.
2022-11-30 17:14:05.392 VERBOSE VirtualTerminal(0)[18] Scripting: WaitFor: polling data for max 60000 ms.
2022-11-30 17:15:05.407 VERBOSE VirtualTerminal(0)[18] Scripting: WaitFor: no data received in 60000 ms.
2022-11-30 17:15:05.407 VERBOSE VirtualTerminal(0)[18] Scripting: WaitFor: last data received 60047 ms ago.
2022-11-30 17:15:05.407 VERBOSE VirtualTerminal(0)[18] Scripting: WaitFor: ScriptEvent.Timeout successfully evaluated.
2022-11-30 17:15:05.411 DEBUG VirtualTerminal(0)[18] Scripting: WaitFor finished with Success.
  Matched script events: timeout: 60000, (timeout: 60000 | (closed | received regex: '[Ll]ogin:'))


This is my exact line of code where timeout coming:
ScriptMatch scriptMatchResult;         
                scriptMatchResult = virtualTerminal.Scripting.WaitFor(ScriptEvent.Timeout, ScriptEvent.Closed, ScriptEvent.FromRegex(prompt));



The same code, Commands are  working for default port ,only for the Custom port commands are not executing and getting timeout error.

This is code for Virtual Terminal binding,

 telnetClient = new Telnet(serverAddress, CustomPortNumber);
virtualTerminal = new VirtualTerminal(80, 50);
virtualTerminal.Scripting.HoldReceivedData = true;
virtualTerminal.Scripting.Timeout = scriptTaskTimeout;
virtualTerminal.Options.LocalEcho = false;
virtualTerminal.Disconnected += new EventHandler(OnDisconnectedHandler);
// virtualTerminal.DataReceived += new DataReceivedEventHandler(OnVTermDataReceivedHandler);
virtualTerminal.DataReceived +=  OnVTermDataReceivedHandler;
virtualTerminal.Options.LocalEcho = true;//this line added or not giving same timeout
virtualTerminal.Bind(telnetClient);

Please help .Thanks in advance
by (73.5k points)
Please provide Verbose log of the communication which is working for you (communication on default port). Either post it here, or send it to support@rebex.net if it contains sensitive data.

Also please note that transmitted password (if any) will be visible in the Verbose logging. Sanitize it if needed.
by (120 points)
Hi Lukus,
I have sent both logs to support@rebex.net  ,Please have  a look and help me .
by (73.5k points)
Thank you for the logs.

When using default port (23) there is a Telnet server running. The data received from the server on port 23 is:

  Welcome to Microsoft Telnet Service

  login:

On the other hand, when using custom port (1880) there is an FTP server running. The data received from the server on port 1880 is:

  220 CesarFTP 0.99e Server Welcome !

In the first case, the server sends login: prompt. Because you are expecting '[Ll]ogin:' to be received from the server, your script works fine.

In the second case, the server does not send login prompt. You are communicating with an FTP server. Expecting '[Ll]ogin:' to be received from an FTP server will always timeout. FTP server does not prompt for username. FTP uses its own commands to authenticate a user. Please see https://datatracker.ietf.org/doc/html/rfc959#section-4

Simply, you cannot use the same script for both Telnet and FTP servers.
by (73.5k points)
Why do you want to use Telnet to script FTP protocol?

It is much more easier to use the FTP component: https://www.rebex.net/ftp-ssl.net/features/
for working with FTP servers.
...