Skip to content

Commit

Permalink
Use Console.ReadLine when stdin redirected
Browse files Browse the repository at this point in the history
  • Loading branch information
masaeedu committed Jan 29, 2018
1 parent afa09b0 commit 49040e4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sshfs/SSHFS.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void Start(Options options)
else if (options.Password)
{
Console.WriteLine("No SSH key file selected, using password auth instead.");
var pass = ReadLine.ReadPassword("Please enter password: ");
var pass = ReadPassword("Please enter password: ");

auths.AddRange(new(string, ConnectionInfo)[]
{
Expand All @@ -122,12 +122,21 @@ static PrivateKeyConnectionInfo PrivateKeyConnectionInfo(Options options)
{
var pkFiles = options.Keys.Select(k =>
options.Password
? new PrivateKeyFile(k, ReadLine.ReadPassword($"Enter passphrase for {k}: "))
? new PrivateKeyFile(k, ReadPassword($"Enter passphrase for {k}: "))
: new PrivateKeyFile(k));

return new PrivateKeyConnectionInfo(options.Host, options.Port, options.Username, pkFiles.ToArray());
}

static string ReadPassword(string prompt)
{
if (!Console.IsInputRedirected)
return ReadLine.ReadPassword(prompt);

Console.WriteLine(prompt);
return Console.ReadLine();
}

static KeyboardInteractiveConnectionInfo KeyboardInteractiveConnectionInfo(Options options, string pass)
{
var auth = new KeyboardInteractiveConnectionInfo(options.Host, options.Port, options.Username);
Expand Down

0 comments on commit 49040e4

Please sign in to comment.