طلب مني القيام بأتمتة تنفيذ عمليات إدارية على سيرفر يدار بواسطة الtelnet وبالبحث وجدت مكتبة خاصة بإدارة الاتصال ببرتوكول telnet اسمها ScriptingTelnet وهي مرفقة.
التعامل مع المكتبة يكون عبر الكود:
string ip = "some server IP";
int port = 23;
int timeout = 10;
try
{
ScriptingTelnet session = new ScriptingTelnet(ip, port, timeout);
// Try to connect
bool connected = session.Connect();
if (connected)
{
// connected successfully
//int startingPrompt = session.WaitFor("Username: "); // this line does not succeed
int startingPrompt = session.WaitFor("login:", " ");
if (startingPrompt == 0)
{
// if the username prompt is found so we send the username
// and wait to recieve our password prompt
session.SendAndWait("login_name", "Password:");
// and now send the password and wait for the next prompt
// in this example I except to recieve a success message
session.SendAndWait("login_password", "Success");
}
else
{
Console.WriteLine("Username prompt was not found");
}
}
else
{
Console.WriteLine("Unable to connect to the server");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}ولكن ما يحدث هو أنها تعطي خطأ في كود التعامل في السطر
int startingPrompt = session.WaitFor("login:", " ");مع نتيجة تنفيذ كالتالي:

ماهو سبب الخطأ وكيف يمكن الاتصال بسيرفر عبر بروتكول telnet عبر الكود بغرض أتمتة تنفيذ عمليات إدارية؟
