Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use ssh config for the default SshClient/SftpClient(string destination) ctor. #229

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading