diff --git a/src/Renci.SshNet/BaseClient.cs b/src/Renci.SshNet/BaseClient.cs index 4b0850b1..df42b31a 100644 --- a/src/Renci.SshNet/BaseClient.cs +++ b/src/Renci.SshNet/BaseClient.cs @@ -550,7 +550,7 @@ namespace Renci.SshNet /// private Timer CreateKeepAliveTimer(TimeSpan dueTime, TimeSpan period) { - return new Timer(state => SendKeepAliveMessage(), Session, dueTime, period); + return new Timer(static state => ((BaseClient)state!).SendKeepAliveMessage(), this, dueTime, period); } private ISession CreateAndConnectSession() diff --git a/src/Renci.SshNet/SftpClient.cs b/src/Renci.SshNet/SftpClient.cs index 77014e9a..95bdfae0 100644 --- a/src/Renci.SshNet/SftpClient.cs +++ b/src/Renci.SshNet/SftpClient.cs @@ -4,7 +4,6 @@ using System.Buffers; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -2120,7 +2119,7 @@ namespace Renci.SshNet { if (!Directory.Exists(sourcePath)) { - throw new FileNotFoundException(string.Format("Source directory not found: {0}", sourcePath)); + throw new FileNotFoundException($"Source directory not found: {sourcePath}"); } var uploadedFiles = new List(); @@ -2170,7 +2169,7 @@ namespace Renci.SshNet if (isDifferent) { - var remoteFileName = string.Format(CultureInfo.InvariantCulture, @"{0}/{1}", destinationPath, localFile.Name); + var remoteFileName = $"{destinationPath}/{localFile.Name}"; try { using (var file = File.OpenRead(localFile.FullName)) @@ -2237,7 +2236,7 @@ namespace Renci.SshNet if (!basePath.EndsWith("/", StringComparison.Ordinal)) #endif { - basePath = string.Format("{0}/", fullPath); + basePath = $"{fullPath}/"; } var result = new List(); @@ -2249,7 +2248,7 @@ namespace Renci.SshNet foreach (var f in files) { result.Add(new SftpFile(_sftpSession, - string.Format(CultureInfo.InvariantCulture, "{0}{1}", basePath, f.Key), + $"{basePath}{f.Key}", f.Value)); } diff --git a/src/Renci.SshNet/SshClient.cs b/src/Renci.SshNet/SshClient.cs index 3051074e..e80b560f 100644 --- a/src/Renci.SshNet/SshClient.cs +++ b/src/Renci.SshNet/SshClient.cs @@ -18,6 +18,11 @@ namespace Renci.SshNet /// private readonly List _forwardedPorts; + /// + /// Cached readonly collection of forwarded ports. + /// + private readonly IEnumerable _forwardedPortsReadOnly; + /// /// Holds a value indicating whether the current instance is disposed. /// @@ -33,7 +38,7 @@ namespace Renci.SshNet { get { - return _forwardedPorts.AsReadOnly(); + return _forwardedPortsReadOnly; } } @@ -137,6 +142,7 @@ namespace Renci.SshNet : base(connectionInfo, ownsConnectionInfo, serviceFactory) { _forwardedPorts = new List(); + _forwardedPortsReadOnly = _forwardedPorts.AsReadOnly(); } ///