/// <summary> /// Login /// </summary> /// <param name="shellFactory"></param> /// <param name="options"></param> /// <returns></returns> private static async Task <ISecureShell> LoginAsync(IShellFactory shellFactory, CliOptions options) { var user = options.GetValueOrDefault <string>("-u", "--user", null); var pw = options.GetValueOrDefault <string>("-p", "--password", null); while (string.IsNullOrEmpty(user)) { Console.WriteLine("User:"******"Password:"******"-t", "--timeout", -1))) { return(await shellFactory.OpenSecureShellAsync( options.GetValue <string>("-h", "--host"), options.GetValueOrDefault("-p", "--port", 22), creds, cts.Token)); } }
/// <summary> /// Open shell to destination /// </summary> /// <param name="factory"></param> /// <param name="host"></param> /// <param name="credentials"></param> /// <returns></returns> public static Task <ISecureShell> OpenSecureShellAsync(this IShellFactory factory, string host, NetworkCredential credentials) => factory.OpenSecureShellAsync(host, credentials, CancellationToken.None);
/// <summary> /// Open shell to destination /// </summary> /// <param name="factory"></param> /// <param name="host"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public static Task <ISecureShell> OpenSecureShellAsync(this IShellFactory factory, string host, string userName, string password) => factory.OpenSecureShellAsync(host, new NetworkCredential(userName, password));
/// <summary> /// Open shell to destination /// </summary> /// <param name="factory"></param> /// <param name="host"></param> /// <param name="port"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="ct"></param> /// <returns></returns> public static Task <ISecureShell> OpenSecureShellAsync(this IShellFactory factory, string host, int port, string userName, string password, CancellationToken ct) => factory.OpenSecureShellAsync(host, port, new NetworkCredential(userName, password), ct);
/// <summary> /// Open shell to destination /// </summary> /// <param name="factory"></param> /// <param name="host"></param> /// <param name="credentials"></param> /// <param name="ct"></param> /// <returns></returns> public static Task <ISecureShell> OpenSecureShellAsync(this IShellFactory factory, string host, NetworkCredential credentials, CancellationToken ct) { return(factory.OpenSecureShellAsync(host, 22, credentials, ct)); }