/// <summary> /// Execute command on Linux server /// </summary> /// <param name="address">Linux server IP Address</param> /// <param name="command">Command to be executed</param> public static string ExecuteCommand(IPAddress address, string command) { TraceFactory.Logger.Debug("Executing command: {0}".FormatWith(command)); SSHProtocol sshProtocol = new SSHProtocol(USER_NAME, PASSWORD, address); if (sshProtocol.Connect()) { // Login as root before executing commands LoginAsRoot(sshProtocol); sshProtocol.Send(command); return(sshProtocol.Send("\n")); } else { return(string.Empty); } }
private void DoConnect() { string host = toolTextHost.Text.Trim(); string user = toolTextUser.Text.Trim(); string password = toolTextPassword.Text.Trim(); string errorMessage = ""; if (host == "") { errorMessage = "Please enter a server address"; goto OnConnectError; } if (user == "") { errorMessage = "Please enter a username"; goto OnConnectError; } if (password == "") { errorMessage = "Please enter a password"; } OnConnectError: if (errorMessage != "") { MessageBox.Show(errorMessage, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (m_networking.Connect(host, user, password)) { m_terminal.ResizeBuffer(); m_networking.Connection.Param.TerminalName = "xterm"; m_networking.Connection.Param.TerminalWidth = m_terminal.VDUBuffer.Columns; m_networking.Connection.Param.TerminalHeight = m_terminal.VDUBuffer.Rows; m_sshProtocol.Connect(); m_networking.SocketClosed += OnSocketClosed; toolTextHost.Enabled = false; toolTextUser.Enabled = false; toolTextPassword.Enabled = false; toolHostConnect.Enabled = false; toolHostDisconnect.Enabled = true; m_terminal.Enabled = true; btnOpenRemote.Enabled = true; menuFileOpenRemote.Enabled = true; menuFileSaveAsRemote.Enabled = true; toolStatusConnected.Text = "Connected"; } }