Skip to content

Instantly share code, notes, and snippets.

@hifi
Created September 12, 2016 03:14
Show Gist options
  • Save hifi/d7c4e3689e28df13893fc0c4fd813706 to your computer and use it in GitHub Desktop.
Save hifi/d7c4e3689e28df13893fc0c4fd813706 to your computer and use it in GitHub Desktop.
SSH.NET SshCommand data writing
diff --git a/src/Renci.SshNet/SshCommand.cs b/src/Renci.SshNet/SshCommand.cs
index 292f67c..23c2d46 100644
--- a/src/Renci.SshNet/SshCommand.cs
+++ b/src/Renci.SshNet/SshCommand.cs
@@ -307,6 +307,9 @@ namespace Renci.SshNet
throw new ArgumentException("EndExecute can only be called once for each asynchronous operation.");
}
+ // always send EOF when closing exec channel
+ _channel.SendEof();
+
// wait for operation to complete (or time out)
WaitOnHandle(_asyncResult.AsyncWaitHandle);
@@ -366,6 +369,26 @@ namespace Renci.SshNet
return Execute();
}
+ /// <summary>
+ /// Sends the data to channel.
+ /// </summary>
+ /// <param name="data">Data.</param>
+ public void SendData(byte[] data)
+ {
+ SendData(data, 0, data.Length);
+ }
+
+ /// <summary>
+ /// Sends the data with offset and size to channel.
+ /// </summary>
+ /// <param name="data">Data.</param>
+ /// <param name="offset">Offset.</param>
+ /// <param name="size">Size.</param>
+ public void SendData(byte[] data, int offset, int size)
+ {
+ _channel.SendData(data, offset, size);
+ }
+
private IChannelSession CreateChannel()
{
var channel = _session.CreateChannelSession();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment