// Protected implementation of Dispose pattern. protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { if (writer != null) { writer.Flush(); } if (reader != null) { reader.Dispose(); } if (stream != null) { stream.Dispose(); } if (client != null) { if (client.IsConnected) { client.Disconnect(); } client.Dispose(); } } disposed = true; }
public void Dispose() { ssh?.Dispose(); scp?.Dispose(); ssh = null; scp = null; }
// Brute SSH public static void SSH(string host, string username, string password) { var SSH = new Renci.SshNet.SshClient(host, username, password); try { SSH.Connect(); SSH.Disconnect(); core.Exit("[SSH] Logged in", output); } catch { output.error = true; core.Exit("[SSH] Failed to login", output); } finally { SSH.Dispose(); } }
public Task StartAsync(CancellationToken cancellationToken) { new Thread(() => { if (_options.SSHSettings != null) { Logs.Configuration.LogInformation($"SSH settings detected, testing connection to {_options.SSHSettings.Username}@{_options.SSHSettings.Server} on port {_options.SSHSettings.Port} ..."); var connection = new Renci.SshNet.SshClient(_options.SSHSettings.CreateConnectionInfo()); connection.HostKeyReceived += (object sender, Renci.SshNet.Common.HostKeyEventArgs e) => { e.CanTrust = true; if (!_options.IsTrustedFingerprint(e.FingerPrint, e.HostKey)) { Logs.Configuration.LogWarning($"SSH host fingerprint for {e.HostKeyName} is untrusted, start BTCPay with -sshtrustedfingerprints \"{Encoders.Hex.EncodeData(e.FingerPrint)}\""); } }; try { connection.Connect(); connection.Disconnect(); Logs.Configuration.LogInformation($"SSH connection succeeded"); } catch (Renci.SshNet.Common.SshAuthenticationException) { Logs.Configuration.LogWarning($"SSH invalid credentials"); } catch (Exception ex) { var message = ex.Message; if (ex is AggregateException aggrEx && aggrEx.InnerException?.Message != null) { message = aggrEx.InnerException.Message; } Logs.Configuration.LogWarning($"SSH connection issue: {message}"); } finally { connection.Dispose(); } } }) { IsBackground = true }.Start();
public void Dispose() { sshClient.Disconnect(); sshClient.Dispose(); }