Skip to content

Commit 34ce2bd

Browse files
authored
Add IBaseClient for BaseClient and ISftpClient to inherit from (#975)
Add IBaseClient for BaseClient and ISftpClient to inherit from
1 parent bd7c02f commit 34ce2bd

File tree

4 files changed

+114
-6
lines changed

4 files changed

+114
-6
lines changed

src/Renci.SshNet/BaseClient.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Renci.SshNet
1313
/// <summary>
1414
/// Serves as base class for client implementations, provides common client functionality.
1515
/// </summary>
16-
public abstract class BaseClient : IDisposable
16+
public abstract class BaseClient : IBaseClient, IDisposable
1717
{
1818
/// <summary>
1919
/// Holds value indicating whether the connection info is owned by this client.
@@ -387,7 +387,7 @@ private void Session_HostKeyReceived(object sender, HostKeyEventArgs e)
387387
}
388388
}
389389

390-
#region IDisposable Members
390+
#region IDisposable Members
391391

392392
private bool _isDisposed;
393393

@@ -446,7 +446,7 @@ protected void CheckDisposed()
446446
Dispose(false);
447447
}
448448

449-
#endregion
449+
#endregion
450450

451451
/// <summary>
452452
/// Stops the keep-alive timer, and waits until all timer callbacks have been

src/Renci.SshNet/IBaseClient.cs

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using Renci.SshNet.Common;
2+
using System;
3+
using System.Net.Sockets;
4+
using System.Threading;
5+
#if FEATURE_TAP
6+
using System.Threading.Tasks;
7+
#endif
8+
9+
namespace Renci.SshNet
10+
{
11+
/// <summary>
12+
/// Serves as base class for client implementations, provides common client functionality.
13+
/// </summary>
14+
public interface IBaseClient
15+
{
16+
/// <summary>
17+
/// Gets the connection info.
18+
/// </summary>
19+
/// <value>
20+
/// The connection info.
21+
/// </value>
22+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
23+
ConnectionInfo ConnectionInfo { get; }
24+
25+
/// <summary>
26+
/// Gets a value indicating whether this client is connected to the server.
27+
/// </summary>
28+
/// <value>
29+
/// <c>true</c> if this client is connected; otherwise, <c>false</c>.
30+
/// </value>
31+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
32+
bool IsConnected { get; }
33+
34+
/// <summary>
35+
/// Gets or sets the keep-alive interval.
36+
/// </summary>
37+
/// <value>
38+
/// The keep-alive interval. Specify negative one (-1) milliseconds to disable the
39+
/// keep-alive. This is the default value.
40+
/// </value>
41+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
42+
TimeSpan KeepAliveInterval { get; set; }
43+
44+
/// <summary>
45+
/// Occurs when an error occurred.
46+
/// </summary>
47+
/// <example>
48+
/// <code source="..\..\src\Renci.SshNet.Tests\Classes\SshClientTest.cs" region="Example SshClient Connect ErrorOccurred" language="C#" title="Handle ErrorOccurred event" />
49+
/// </example>
50+
event EventHandler<ExceptionEventArgs> ErrorOccurred;
51+
52+
/// <summary>
53+
/// Occurs when host key received.
54+
/// </summary>
55+
/// <example>
56+
/// <code source="..\..\src\Renci.SshNet.Tests\Classes\SshClientTest.cs" region="Example SshClient Connect HostKeyReceived" language="C#" title="Handle HostKeyReceived event" />
57+
/// </example>
58+
event EventHandler<HostKeyEventArgs> HostKeyReceived;
59+
60+
/// <summary>
61+
/// Connects client to the server.
62+
/// </summary>
63+
/// <exception cref="InvalidOperationException">The client is already connected.</exception>
64+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
65+
/// <exception cref="SocketException">Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.</exception>
66+
/// <exception cref="SshConnectionException">SSH session could not be established.</exception>
67+
/// <exception cref="SshAuthenticationException">Authentication of SSH session failed.</exception>
68+
/// <exception cref="ProxyException">Failed to establish proxy connection.</exception>
69+
void Connect();
70+
71+
#if FEATURE_TAP
72+
/// <summary>
73+
/// Asynchronously connects client to the server.
74+
/// </summary>
75+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
76+
/// <returns>A <see cref="Task"/> that represents the asynchronous connect operation.
77+
/// </returns>
78+
/// <exception cref="InvalidOperationException">The client is already connected.</exception>
79+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
80+
/// <exception cref="SocketException">Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.</exception>
81+
/// <exception cref="SshConnectionException">SSH session could not be established.</exception>
82+
/// <exception cref="SshAuthenticationException">Authentication of SSH session failed.</exception>
83+
/// <exception cref="ProxyException">Failed to establish proxy connection.</exception>
84+
Task ConnectAsync(CancellationToken cancellationToken);
85+
#endif
86+
87+
/// <summary>
88+
/// Disconnects client from the server.
89+
/// </summary>
90+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
91+
void Disconnect();
92+
93+
/// <summary>
94+
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
95+
/// </summary>
96+
void Dispose();
97+
98+
/// <summary>
99+
/// Sends a keep-alive message to the server.
100+
/// </summary>
101+
/// <remarks>
102+
/// Use <see cref="KeepAliveInterval"/> to configure the client to send a keep-alive at regular
103+
/// intervals.
104+
/// </remarks>
105+
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
106+
void SendKeepAlive();
107+
}
108+
}

src/Renci.SshNet/ISftpClient.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Renci.SshNet
1414
/// <summary>
1515
/// Implementation of the SSH File Transfer Protocol (SFTP) over SSH.
1616
/// </summary>
17-
public interface ISftpClient : IDisposable
17+
public interface ISftpClient : IBaseClient, IDisposable
1818
{
1919
/// <summary>
2020
/// Gets or sets the maximum size of the buffer in bytes.
@@ -720,7 +720,7 @@ public interface ISftpClient : IDisposable
720720
/// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
721721
/// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
722722
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
723-
Task<IEnumerable<SftpFile>> ListDirectoryAsync(string path, CancellationToken cancellationToken);
723+
Task<IEnumerable<ISftpFile>> ListDirectoryAsync(string path, CancellationToken cancellationToken);
724724
#endif
725725

726726
/// <summary>

src/Renci.SshNet/SftpClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public IEnumerable<ISftpFile> ListDirectory(string path, Action<int> listCallbac
552552
/// <exception cref="SftpPermissionDeniedException">Permission to list the contents of the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
553553
/// <exception cref="SshException">A SSH error where <see cref="Exception.Message" /> is the message from the remote host.</exception>
554554
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
555-
public async Task<IEnumerable<SftpFile>> ListDirectoryAsync(string path, CancellationToken cancellationToken)
555+
public async Task<IEnumerable<ISftpFile>> ListDirectoryAsync(string path, CancellationToken cancellationToken)
556556
{
557557
base.CheckDisposed();
558558
if (path == null)

0 commit comments

Comments
 (0)