Skip to content

Commit

Permalink
Don't use ssh config for the default SshClient/SftpClient(string dest…
Browse files Browse the repository at this point in the history
…ination) ctor. (#229)
  • Loading branch information
tmds authored Sep 20, 2024
1 parent 6aef1df commit 673de5e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using Microsoft.Extensions.Logging;
using Tmds.Ssh;

using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
using var sshClient = new SshClient("localhost", loggerFactory);
using var sshClient = new SshClient("localhost", SshConfigSettings.DefaultConfig, loggerFactory);
using var process = await sshClient.ExecuteAsync("echo 'hello world!'");
(bool isError, string? line) = await process.ReadLineAsync();
Console.WriteLine(line);
Expand All @@ -55,8 +55,11 @@ namespace Tmds.Ssh;

class SshClient : IDisposable
{
SshClient(string destination, ILoggerFactory? loggerFactory = null); // uses SshConfigSettings.DefaultConfig.
// Connect to the destination. No additional config.
SshClient(string destination, ILoggerFactory? loggerFactory = null);
// Use OpenSSH config files and options to configure the client.
SshClient(string destination, SshConfigSettings configSettings, ILoggerFactory? loggerFactory = null);
// Use the .NET SshClientSettings API to configure the client.
SshClient(SshClientSettings settings, ILoggerFactory? loggerFactory = null);

// Calling ConnectAsync is optional when SshClientSettings.AutoConnect is set (default).
Expand Down Expand Up @@ -119,6 +122,7 @@ class SftpClient : IDisposable
const UnixFilePermissions DefaultCreateFilePermissions; // = '-rwxrwxrwx'.
// The SftpClient owns the connection.
SftpClient(string destination, ILoggerFactory? loggerFactory = null, SftpClientOptions? options = null);
SftpClient(string destination, SshConfigSettings configSettings, ILoggerFactory? loggerFactory = null, SftpClientOptions? options = null);
SftpClient(SshClientSettings settings, ILoggerFactory? loggerFactory = null, SftpClientOptions? options = null);

Expand Down
2 changes: 1 addition & 1 deletion examples/scp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

string sshDestination = source.SshDestination ?? destination.SshDestination!;

using SshClient client = new SshClient(sshDestination);
using SshClient client = new SshClient(sshDestination, SshConfigSettings.DefaultConfig);

await client.ConnectAsync();

Expand Down
4 changes: 4 additions & 0 deletions src/Tmds.Ssh/SftpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ enum State
internal SshClient SshClient => _client;
internal bool IsDisposed => _state == State.Disposed;

public SftpClient(string destination, ILoggerFactory? loggerFactory = null, SftpClientOptions? options = null) :
this(destination, SshConfigSettings.NoConfig, loggerFactory, options)
{ }

public SftpClient(string destination, SshConfigSettings configSettings, ILoggerFactory? loggerFactory = null, SftpClientOptions? options = null) :
this(new SshClient(destination, configSettings, loggerFactory), options, ownsClient: true)
{ }
Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.Ssh/SshClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum State
internal bool IsDisposed => _state == State.Disposed;

public SshClient(string destination, ILoggerFactory? loggerFactory = null) :
this(destination, SshConfigSettings.DefaultConfig, loggerFactory)
this(destination, SshConfigSettings.NoConfig, loggerFactory)
{ }

public SshClient(SshClientSettings settings, ILoggerFactory? loggerFactory = null) :
Expand Down
File renamed without changes.

0 comments on commit 673de5e

Please sign in to comment.