private void ExCmd() { string cmd = SshConnection.ExecBashCommand(textBox_cmd.Text); if (cmd == null) { textBox_text.AppendText("Error executing command!" + Environment.NewLine); } else { cmd = Regex.Replace(cmd, "\n\r", "\n"); cmd = Regex.Replace(cmd, "\n", Environment.NewLine); textBox_text.AppendText(Environment.NewLine + "[" + SshConnection.sshexec.Username + "@" + SshConnection.sshexec.Host + "]: " + textBox_cmd.Text + Environment.NewLine + cmd + Environment.NewLine); } }
public string GetFirstSSH() { //FileLists fil_lst = new FileLists(); string return_value = null; SshConnection.sshexec.Password = SshSettings.pwd; //изменитьToolStripMenuItem.Enabled = false; ////TODO Соединение с сервером, получение списка файлов try { listBox_log.Items.Add("Connecting..."); Application.DoEvents(); if (!SshConnection.sshexec.Connected) { SshConnection.sshexec.Connect(); } Application.DoEvents(); listBox_log.Items.Add("Connected"); string first_cmd = SshConnection.ExecBashCommand("ls -la"); first_cmd = Regex.Replace(first_cmd, "\n\r", "\n"); first_cmd = Regex.Replace(first_cmd, "\n", Environment.NewLine); return_value = "Server version: " + SshConnection.sshexec.ServerVersion + Environment.NewLine + "Chiper algorytm: " + SshConnection.sshexec.Cipher + Environment.NewLine + first_cmd; listBox_log.Items.Add("Disconnecting..."); //FileLists.sshexec.Close(); listBox_log.Items.Add("OK"); } catch (Exception ex) { MessageBox.Show("Проверьте настройки подключения" + Environment.NewLine + "Произошла ошибка: " + ex.Message); //изменитьToolStripMenuItem.Enabled = true; listBox_log.Items.Add("ERROR"); return_value = null; } finally { if (return_value != null) { this.Close(); } } return(return_value); }