diff --git a/Renci.SshClient/Renci.SshNet/BaseClient.cs b/Renci.SshClient/Renci.SshNet/BaseClient.cs
index e398ca58..3beca30b 100644
--- a/Renci.SshClient/Renci.SshNet/BaseClient.cs
+++ b/Renci.SshClient/Renci.SshNet/BaseClient.cs
@@ -180,17 +180,7 @@ namespace Renci.SshNet
}
- ///
- /// Ensures that client is connected.
- ///
- /// When client not connected.
- protected void EnsureConnection()
- {
- if (!this.Session.IsConnected)
- throw new SshConnectionException("Client not connected.");
- }
-
- private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
+ private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
{
if (this.ErrorOccurred != null)
{
diff --git a/Renci.SshClient/Renci.SshNet/NetConfClient.cs b/Renci.SshClient/Renci.SshNet/NetConfClient.cs
index d2c6f198..dad27451 100644
--- a/Renci.SshClient/Renci.SshNet/NetConfClient.cs
+++ b/Renci.SshClient/Renci.SshNet/NetConfClient.cs
@@ -116,7 +116,6 @@ namespace Renci.SshNet
{
get
{
- this.EnsureConnection();
return this._netConfSession.ServerCapabilities;
}
}
@@ -129,7 +128,6 @@ namespace Renci.SshNet
{
get
{
- this.EnsureConnection();
return this._netConfSession.ClientCapabilities;
}
}
@@ -150,7 +148,6 @@ namespace Renci.SshNet
/// Client is not connected.
public XmlDocument SendReceiveRpc(XmlDocument rpc)
{
- this.EnsureConnection();
return this._netConfSession.SendReceiveRpc(rpc, this.AutomaticMessageIdHandling);
}
@@ -173,8 +170,6 @@ namespace Renci.SshNet
/// Client is not connected.
public XmlDocument SendCloseRpc()
{
- this.EnsureConnection();
-
XmlDocument rpc = new XmlDocument();
rpc.LoadXml("");
diff --git a/Renci.SshClient/Renci.SshNet/ScpClient.NET.cs b/Renci.SshClient/Renci.SshNet/ScpClient.NET.cs
index 66ecbe8b..c7a95fb8 100644
--- a/Renci.SshClient/Renci.SshNet/ScpClient.NET.cs
+++ b/Renci.SshClient/Renci.SshNet/ScpClient.NET.cs
@@ -31,9 +31,6 @@ namespace Renci.SshNet
if (string.IsNullOrEmpty(filename))
throw new ArgumentException("filename");
- // Ensure that connection is established.
- this.EnsureConnection();
-
using (var input = new PipeStream())
using (var channel = this.Session.CreateChannel())
{
@@ -70,9 +67,6 @@ namespace Renci.SshNet
if (string.IsNullOrEmpty(filename))
throw new ArgumentException("filename");
- // Ensure that connection is established.
- this.EnsureConnection();
-
using (var input = new PipeStream())
using (var channel = this.Session.CreateChannel())
{
@@ -108,9 +102,6 @@ namespace Renci.SshNet
if (string.IsNullOrEmpty(filename))
throw new ArgumentException("filename");
- // Ensure that connection is established.
- this.EnsureConnection();
-
using (var input = new PipeStream())
using (var channel = this.Session.CreateChannel())
{
@@ -146,9 +137,6 @@ namespace Renci.SshNet
if (string.IsNullOrEmpty(directoryName))
throw new ArgumentException("directoryName");
- // Ensure that connection is established.
- this.EnsureConnection();
-
using (var input = new PipeStream())
using (var channel = this.Session.CreateChannel())
{
diff --git a/Renci.SshClient/Renci.SshNet/ScpClient.cs b/Renci.SshClient/Renci.SshNet/ScpClient.cs
index e628a7ab..4e2a157f 100644
--- a/Renci.SshClient/Renci.SshNet/ScpClient.cs
+++ b/Renci.SshClient/Renci.SshNet/ScpClient.cs
@@ -144,9 +144,6 @@ namespace Renci.SshNet
/// Remote host file name.
public void Upload(Stream source, string filename)
{
- // Ensure that connection is established.
- this.EnsureConnection();
-
using (var input = new PipeStream())
using (var channel = this.Session.CreateChannel())
{
@@ -184,9 +181,6 @@ namespace Renci.SshNet
if (destination == null)
throw new ArgumentNullException("destination");
- // Ensure that connection is established.
- this.EnsureConnection();
-
using (var input = new PipeStream())
using (var channel = this.Session.CreateChannel())
{
diff --git a/Renci.SshClient/Renci.SshNet/Session.cs b/Renci.SshClient/Renci.SshNet/Session.cs
index 1ef9cc5d..e803299f 100644
--- a/Renci.SshClient/Renci.SshNet/Session.cs
+++ b/Renci.SshClient/Renci.SshNet/Session.cs
@@ -652,8 +652,8 @@ namespace Renci.SshNet
/// The message.
internal void SendMessage(Message message)
{
- if (this._socket == null || !this._socket.Connected)
- return;
+ if (!this.IsConnected)
+ throw new SshConnectionException("Client not connected.");
if (this._keyExchangeInProgress && !(message is IKeyExchangedAllowed))
{
diff --git a/Renci.SshClient/Renci.SshNet/SftpClient.NET.cs b/Renci.SshClient/Renci.SshNet/SftpClient.NET.cs
index b6a4c974..10e5f9a5 100644
--- a/Renci.SshClient/Renci.SshNet/SftpClient.NET.cs
+++ b/Renci.SshClient/Renci.SshNet/SftpClient.NET.cs
@@ -51,9 +51,6 @@ namespace Renci.SshNet
if (destinationPath.IsNullOrWhiteSpace())
throw new ArgumentException("destDir");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var asyncResult = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state);
this.ExecuteThread(() =>
diff --git a/Renci.SshClient/Renci.SshNet/SftpClient.cs b/Renci.SshClient/Renci.SshNet/SftpClient.cs
index 86196ae6..86af9a98 100644
--- a/Renci.SshClient/Renci.SshNet/SftpClient.cs
+++ b/Renci.SshClient/Renci.SshNet/SftpClient.cs
@@ -142,10 +142,7 @@ namespace Renci.SshNet
{
if (path == null)
throw new ArgumentNullException("path");
-
- // Ensure that connection is established.
- this.EnsureConnection();
-
+
this._sftpSession.ChangeDirectory(path);
}
@@ -179,9 +176,6 @@ namespace Renci.SshNet
if (path.IsNullOrWhiteSpace())
throw new ArgumentException(path);
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
this._sftpSession.RequestMkDir(fullPath);
@@ -200,9 +194,6 @@ namespace Renci.SshNet
if (path.IsNullOrWhiteSpace())
throw new ArgumentException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
this._sftpSession.RequestRmDir(fullPath);
@@ -221,9 +212,6 @@ namespace Renci.SshNet
if (path.IsNullOrWhiteSpace())
throw new ArgumentException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
this._sftpSession.RequestRemove(fullPath);
@@ -262,9 +250,6 @@ namespace Renci.SshNet
if (newPath == null)
throw new ArgumentNullException("newPath");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var oldFullPath = this._sftpSession.GetCanonicalPath(oldPath);
var newFullPath = this._sftpSession.GetCanonicalPath(newPath);
@@ -296,9 +281,6 @@ namespace Renci.SshNet
if (linkPath.IsNullOrWhiteSpace())
throw new ArgumentException("linkPath");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
var linkFullPath = this._sftpSession.GetCanonicalPath(linkPath);
@@ -394,9 +376,6 @@ namespace Renci.SshNet
if (path == null)
throw new ArgumentNullException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
var attributes = this._sftpSession.RequestLStat(fullPath);
@@ -418,9 +397,6 @@ namespace Renci.SshNet
if (path.IsNullOrWhiteSpace())
throw new ArgumentException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
// Try to open as a file
@@ -490,9 +466,6 @@ namespace Renci.SshNet
if (output == null)
throw new ArgumentNullException("output");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var asyncResult = new SftpDownloadAsyncResult(asyncCallback, state);
this.ExecuteThread(() =>
@@ -643,9 +616,6 @@ namespace Renci.SshNet
else
flags |= Flags.CreateNew;
- // Ensure that connection is established.
- this.EnsureConnection();
-
var asyncResult = new SftpUploadAsyncResult(asyncCallback, state);
this.ExecuteThread(() =>
@@ -704,9 +674,6 @@ namespace Renci.SshNet
if (path == null)
throw new ArgumentNullException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
return this._sftpSession.RequestStatVfs(fullPath);
@@ -1280,9 +1247,6 @@ namespace Renci.SshNet
if (path == null)
throw new ArgumentNullException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
var handle = this._sftpSession.RequestOpenDir(fullPath);
@@ -1335,9 +1299,6 @@ namespace Renci.SshNet
if (path.IsNullOrWhiteSpace())
throw new ArgumentException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
var handle = this._sftpSession.RequestOpen(fullPath, Flags.Read);
@@ -1388,9 +1349,6 @@ namespace Renci.SshNet
if (path.IsNullOrWhiteSpace())
throw new ArgumentException("path");
- // Ensure that connection is established.
- this.EnsureConnection();
-
var fullPath = this._sftpSession.GetCanonicalPath(path);
var handle = this._sftpSession.RequestOpen(fullPath, flags);
diff --git a/Renci.SshClient/Renci.SshNet/SshClient.cs b/Renci.SshClient/Renci.SshNet/SshClient.cs
index 27c9bd06..e3a307cc 100644
--- a/Renci.SshClient/Renci.SshNet/SshClient.cs
+++ b/Renci.SshClient/Renci.SshNet/SshClient.cs
@@ -156,9 +156,6 @@ namespace Renci.SshNet
if (port == null)
throw new ArgumentNullException("port");
- // Ensure that connection is established.
- this.EnsureConnection();
-
if (port.Session != null && port.Session != this.Session)
throw new InvalidOperationException("Forwarded port is already added to a different client.");
@@ -206,9 +203,6 @@ namespace Renci.SshNet
/// or is null.
public SshCommand CreateCommand(string commandText, Encoding encoding)
{
- // Ensure that connection is established.
- this.EnsureConnection();
-
return new SshCommand(this.Session, commandText, encoding);
}
@@ -252,9 +246,6 @@ namespace Renci.SshNet
///
public Shell CreateShell(Stream input, Stream output, Stream extendedOutput, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary terminalModes, int bufferSize)
{
- // Ensure that connection is established.
- this.EnsureConnection();
-
return new Shell(this.Session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize);
}
@@ -388,9 +379,6 @@ namespace Renci.SshNet
///
public ShellStream CreateShellStream(string terminalName, uint columns, uint rows, uint width, uint height, int bufferSize, IDictionary terminalModeValues)
{
- // Ensure that connection is established.
- this.EnsureConnection();
-
return new ShellStream(this.Session, terminalName, columns, rows, width, height, bufferSize, terminalModeValues);
}