private static string GetStringFromUrl(Uri uri) { using (WebClient client = new WebClient()) { try { return(client.DownloadString(uri)); } catch (Exception ex) { Outil.Ecrire_Erreur(ex); throw; } } }
internal static void ExecCommand(SshClients.I_SshClient client, string commandText) { try { client.RunCommand(commandText); } catch (ArgumentException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(@" Erreur : votre commande est vide. "); Console.ForegroundColor = ConsoleColor.Gray; } catch (Exception ex) { Outil.Ecrire_Erreur(ex); } }
internal void GetStringFromExecCommand(SshClients.I_SshClient client, string commandText) { try { this.LastResult = client.RunCommand(commandText).Result; this.m_menu = new Menu(LastResult); } catch (ArgumentException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(@" Erreur : votre commande est vide. "); Console.ForegroundColor = ConsoleColor.Gray; } catch (Exception ex) { Outil.Ecrire_Erreur(ex); } }
//private const string HOSTNAME_OR_IP = "azuril.ddns.net"; //private const string USERNAME = "******"; #region ClientGoHSsh private void Init_01() { ConsoleManager.Show(); string[] ts_Lines = File.ReadAllLines(m_config_Path); if (string.IsNullOrWhiteSpace(ts_Lines[0])) { Console.WriteLine(@" Pas de parametre dans le fichier : "); Console.WriteLine(m_config_Path); return; } else { string ip = ts_Lines[0]; string username = ts_Lines[1]; string password = ts_Lines[2]; Console.WriteLine(@" connection a "); Console.WriteLine(username + @"@" + ip); Console.WriteLine(@" en cour ... "); AuthenticationMethod[] t_Auth = { new PasswordAuthenticationMethod(username, password) }; ConnectionInfo connectionInfo = new ConnectionInfo(ip, username, t_Auth); try { //throw new ApplicationException(" mock "); this.m_client = new SshClients.SshClient2(ip, username, password); this.m_client.Connect(); Console.WriteLine(@" connection reussi. "); if (this.m_bw == null) { this.m_bw = new BackgroundWorker(); } if (!this.m_bw.IsBusy) { this.m_bw = new BackgroundWorker(); const string bashGetCsv = "cat ~/Desktop/bash.csv.txt"; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(@" bash : "); Console.WriteLine(bashGetCsv); Console.ForegroundColor = ConsoleColor.Gray; m_bw.DoWork += (sender, args) => GetStringFromExecCommand(m_client, bashGetCsv); m_bw.RunWorkerCompleted += M_bw_RunWorkerCompleted; m_bw.RunWorkerAsync(); } } catch (Exception ex) { Outil.Ecrire_Erreur(ex); this.m_client = new SshClients.SshClientBouchon(connectionInfo); Console.WriteLine(@" bouchon. "); //throw; } } Console.WriteLine(@" fin ClientGoHSsh() "); }