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.6k 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)
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.6k 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.6k 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.6k 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.
...