我有一个 C# WPF 应用程序,它建立 Telnet 连接以将一些内容从 Windows 系统写入 Linux 系统上的文件。假设我有一些这样的文字。
这是一段文本 \r\n 后跟一个新行。
代码的大致流程如下:
string ipAddress = "11.11.11.11";
int port = 66;
TelnetConnection tc = new TelnetConnection(ipAddress, port);
string s = tc.Login("root", "password", 100);
string prompt = s.TrimEnd();
if (prompt != "$" && prompt != "#"){
throw new Exception("Connection failed");
}
tc.WriteLine("echo $'Here is a bit\tof text \r\n Followed by a new line.' >> MyFile.txt");
Run Code Online (Sandbox Code Playgroud)
这是我使用的 TelnetConnection 类:\
enum Verbs
{
WILL = 251,
WONT = 252,
DO = 253, …Run Code Online (Sandbox Code Playgroud)