|
|
@@ -17,41 +17,95 @@ namespace Renci.SshNet
|
|
|
public partial class SftpClient : BaseClient
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// Holds SftpSession instance that used to communicate to the SFTP server
|
|
|
+ /// Holds the <see cref="SftpSession"/> instance that used to communicate to the
|
|
|
+ /// SFTP server.
|
|
|
/// </summary>
|
|
|
private SftpSession _sftpSession;
|
|
|
|
|
|
- private readonly bool _disposeConnectionInfo;
|
|
|
+ /// <summary>
|
|
|
+ /// Holds the operation timeout.
|
|
|
+ /// </summary>
|
|
|
+ private TimeSpan _operationTimeout;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Holds the size of the buffer.
|
|
|
+ /// </summary>
|
|
|
+ private uint _bufferSize;
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the operation timeout.
|
|
|
/// </summary>
|
|
|
- /// <value>The operation timeout.</value>
|
|
|
- public TimeSpan OperationTimeout { get; set; }
|
|
|
+ /// <value>
|
|
|
+ /// The timeout to wait until an operation completes. The default value is negative
|
|
|
+ /// one (-1) milliseconds, which indicates an infinite time-out period.
|
|
|
+ /// </value>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
+ public TimeSpan OperationTimeout
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ CheckDisposed();
|
|
|
+ return _operationTimeout;
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ CheckDisposed();
|
|
|
+ _operationTimeout = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the size of the buffer.
|
|
|
/// </summary>
|
|
|
- /// <value>The size of the buffer.</value>
|
|
|
- public uint BufferSize { get; set; }
|
|
|
+ /// <value>
|
|
|
+ /// The size of the buffer. The default buffer size is 16384 bytes.
|
|
|
+ /// </value>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
+ public uint BufferSize
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ CheckDisposed();
|
|
|
+ return _bufferSize;
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ CheckDisposed();
|
|
|
+ _bufferSize = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets remote working directory.
|
|
|
/// </summary>
|
|
|
+ /// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public string WorkingDirectory
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- if (this._sftpSession == null)
|
|
|
- return null;
|
|
|
- return this._sftpSession.WorkingDirectory;
|
|
|
+ CheckDisposed();
|
|
|
+ if (_sftpSession == null)
|
|
|
+ throw new SshConnectionException("Client not connected.");
|
|
|
+ return _sftpSession.WorkingDirectory;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets sftp protocol version.
|
|
|
/// </summary>
|
|
|
- public int ProtocolVersion { get; private set; }
|
|
|
+ /// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
+ public int ProtocolVersion
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ CheckDisposed();
|
|
|
+ if (_sftpSession == null)
|
|
|
+ throw new SshConnectionException("Client not connected.");
|
|
|
+ return (int) _sftpSession.ProtocolVersion;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
@@ -61,10 +115,8 @@ namespace Renci.SshNet
|
|
|
/// <param name="connectionInfo">The connection info.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is <b>null</b>.</exception>
|
|
|
public SftpClient(ConnectionInfo connectionInfo)
|
|
|
- : base(connectionInfo)
|
|
|
+ : this(connectionInfo, false)
|
|
|
{
|
|
|
- this.OperationTimeout = new TimeSpan(0, 0, 0, 0, -1);
|
|
|
- this.BufferSize = 1024 * 16;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -79,9 +131,8 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="F:System.Net.IPEndPoint.MinPort"/> and <see cref="System.Net.IPEndPoint.MaxPort"/>.</exception>
|
|
|
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
|
|
|
public SftpClient(string host, int port, string username, string password)
|
|
|
- : this(new PasswordConnectionInfo(host, port, username, password))
|
|
|
+ : this(new PasswordConnectionInfo(host, port, username, password), true)
|
|
|
{
|
|
|
- this._disposeConnectionInfo = true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -109,9 +160,8 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="F:System.Net.IPEndPoint.MinPort"/> and <see cref="System.Net.IPEndPoint.MaxPort"/>.</exception>
|
|
|
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
|
|
|
public SftpClient(string host, int port, string username, params PrivateKeyFile[] keyFiles)
|
|
|
- : this(new PrivateKeyConnectionInfo(host, port, username, keyFiles))
|
|
|
+ : this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), true)
|
|
|
{
|
|
|
- this._disposeConnectionInfo = true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -127,6 +177,23 @@ namespace Renci.SshNet
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Initializes a new instance of the <see cref="SftpClient"/> class.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="connectionInfo">The connection info.</param>
|
|
|
+ /// <param name="ownsConnectionInfo">Specified whether this instance owns the connection info.</param>
|
|
|
+ /// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is null.</exception>
|
|
|
+ /// <remarks>
|
|
|
+ /// If <paramref name="ownsConnectionInfo"/> is <c>true</c>, then the
|
|
|
+ /// connection info will be disposed when this instance is disposed.
|
|
|
+ /// </remarks>
|
|
|
+ private SftpClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo)
|
|
|
+ : base(connectionInfo, ownsConnectionInfo)
|
|
|
+ {
|
|
|
+ this.OperationTimeout = new TimeSpan(0, 0, 0, 0, -1);
|
|
|
+ this.BufferSize = 1024 * 16;
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -138,8 +205,11 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SftpPermissionDeniedException">Permission to change directory denied by remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="SftpPathNotFoundException">The path in <paramref name="path"/> was not found on the remote host.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void ChangeDirectory(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path == null)
|
|
|
throw new ArgumentNullException("path");
|
|
|
|
|
|
@@ -159,10 +229,10 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SftpPermissionDeniedException">Permission to change permission on the path(s) was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="SftpPathNotFoundException">The path in <paramref name="path"/> was not found on the remote host.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void ChangePermissions(string path, short mode)
|
|
|
{
|
|
|
var file = this.Get(path);
|
|
|
-
|
|
|
file.SetPermissions(mode);
|
|
|
}
|
|
|
|
|
|
@@ -174,8 +244,11 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to create the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void CreateDirectory(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path.IsNullOrWhiteSpace())
|
|
|
throw new ArgumentException(path);
|
|
|
|
|
|
@@ -195,8 +268,11 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to delete the directory was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void DeleteDirectory(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path.IsNullOrWhiteSpace())
|
|
|
throw new ArgumentException("path");
|
|
|
|
|
|
@@ -216,8 +292,11 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to delete the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void DeleteFile(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path.IsNullOrWhiteSpace())
|
|
|
throw new ArgumentException("path");
|
|
|
|
|
|
@@ -238,6 +317,7 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to rename the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void RenameFile(string oldPath, string newPath)
|
|
|
{
|
|
|
this.RenameFile(oldPath, newPath, false);
|
|
|
@@ -249,13 +329,15 @@ namespace Renci.SshNet
|
|
|
/// <param name="oldPath">Path to the old file location.</param>
|
|
|
/// <param name="newPath">Path to the new file location.</param>
|
|
|
/// <param name="isPosix">if set to <c>true</c> then perform a posix rename.</param>
|
|
|
- /// <exception cref="System.ArgumentNullException">oldPath</exception>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="oldPath" /> is <b>null</b>. <para>-or-</para> or <paramref name="newPath" /> is <b>null</b>.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to rename the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void RenameFile(string oldPath, string newPath, bool isPosix)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (oldPath == null)
|
|
|
throw new ArgumentNullException("oldPath");
|
|
|
|
|
|
@@ -288,8 +370,11 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to create the symbolic link was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void SymbolicLink(string path, string linkPath)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path.IsNullOrWhiteSpace())
|
|
|
throw new ArgumentException("path");
|
|
|
|
|
|
@@ -318,8 +403,11 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.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>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public IEnumerable<SftpFile> ListDirectory(string path, Action<int> listCallback = null)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
return InternalListDirectory(path, listCallback);
|
|
|
}
|
|
|
|
|
|
@@ -333,8 +421,11 @@ namespace Renci.SshNet
|
|
|
/// <returns>
|
|
|
/// An <see cref="IAsyncResult" /> that references the asynchronous operation.
|
|
|
/// </returns>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public IAsyncResult BeginListDirectory(string path, AsyncCallback asyncCallback, object state, Action<int> listCallback = null)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
var asyncResult = new SftpListDirectoryAsyncResult(asyncCallback, state);
|
|
|
|
|
|
this.ExecuteThread(() =>
|
|
|
@@ -386,11 +477,13 @@ namespace Renci.SshNet
|
|
|
/// </summary>
|
|
|
/// <param name="path">The path.</param>
|
|
|
/// <returns>Reference to <see cref="Renci.SshNet.Sftp.SftpFile"/> file object.</returns>
|
|
|
- /// <exception cref="System.ArgumentNullException">path</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFile Get(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path == null)
|
|
|
throw new ArgumentNullException("path");
|
|
|
|
|
|
@@ -413,8 +506,11 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message"/> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public bool Exists(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path.IsNullOrWhiteSpace())
|
|
|
throw new ArgumentException("path");
|
|
|
|
|
|
@@ -441,11 +537,14 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
public void DownloadFile(string path, Stream output, Action<ulong> downloadCallback = null)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
this.InternalDownloadFile(path, output, null, downloadCallback);
|
|
|
}
|
|
|
|
|
|
@@ -457,13 +556,12 @@ namespace Renci.SshNet
|
|
|
/// <returns>
|
|
|
/// An <see cref="IAsyncResult" /> that references the asynchronous operation.
|
|
|
/// </returns>
|
|
|
- /// <exception cref="System.ArgumentException">path</exception>
|
|
|
- /// <exception cref="System.ArgumentNullException">output</exception>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="output" /> is <b>null</b>.</exception>
|
|
|
/// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains whitespace characters.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
@@ -481,13 +579,12 @@ namespace Renci.SshNet
|
|
|
/// <returns>
|
|
|
/// An <see cref="IAsyncResult" /> that references the asynchronous operation.
|
|
|
/// </returns>
|
|
|
- /// <exception cref="System.ArgumentException">path</exception>
|
|
|
- /// <exception cref="System.ArgumentNullException">output</exception>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="output" /> is <b>null</b>.</exception>
|
|
|
/// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains whitespace characters.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
@@ -507,18 +604,19 @@ namespace Renci.SshNet
|
|
|
/// <returns>
|
|
|
/// An <see cref="IAsyncResult" /> that references the asynchronous operation.
|
|
|
/// </returns>
|
|
|
- /// <exception cref="System.ArgumentException">path</exception>
|
|
|
- /// <exception cref="System.ArgumentNullException">output</exception>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="output" /> is <b>null</b>.</exception>
|
|
|
/// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains whitespace characters.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to perform the operation was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="output" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
public IAsyncResult BeginDownloadFile(string path, Stream output, AsyncCallback asyncCallback, object state, Action<ulong> downloadCallback = null)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path.IsNullOrWhiteSpace())
|
|
|
throw new ArgumentException("path");
|
|
|
|
|
|
@@ -579,6 +677,7 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to upload the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
@@ -599,11 +698,14 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.SftpPermissionDeniedException">Permission to upload the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
public void UploadFile(Stream input, string path, bool canOverride, Action<ulong> uploadCallback = null)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
var flags = Flags.Write | Flags.Truncate;
|
|
|
|
|
|
if (canOverride)
|
|
|
@@ -627,6 +729,7 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.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>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
@@ -649,6 +752,7 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.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>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
@@ -673,6 +777,7 @@ namespace Renci.SshNet
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.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>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
@@ -693,18 +798,19 @@ namespace Renci.SshNet
|
|
|
/// <returns>
|
|
|
/// An <see cref="IAsyncResult" /> that references the asynchronous operation.
|
|
|
/// </returns>
|
|
|
- /// <exception cref="System.ArgumentNullException">input</exception>
|
|
|
- /// <exception cref="System.ArgumentException">path</exception>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception>
|
|
|
/// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains whitespace characters.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="Renci.SshNet.Common.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>
|
|
|
/// <exception cref="T:Renci.SshNet.Common.SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
/// <remarks>
|
|
|
/// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream.
|
|
|
/// </remarks>
|
|
|
public IAsyncResult BeginUploadFile(Stream input, string path, bool canOverride, AsyncCallback asyncCallback, object state, Action<ulong> uploadCallback = null)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (input == null)
|
|
|
throw new ArgumentNullException("input");
|
|
|
|
|
|
@@ -768,11 +874,13 @@ namespace Renci.SshNet
|
|
|
/// </summary>
|
|
|
/// <param name="path">The path.</param>
|
|
|
/// <returns>Reference to <see cref="Renci.SshNet.Sftp.SftpFileSytemInformation"/> object that contains file status information.</returns>
|
|
|
- /// <exception cref="System.ArgumentNullException">path</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path" /> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileSytemInformation GetStatus(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (path == null)
|
|
|
throw new ArgumentNullException("path");
|
|
|
|
|
|
@@ -792,8 +900,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to append the lines to. The file is created if it does not already exist.</param>
|
|
|
/// <param name="contents">The lines to append to the file.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is<b>null</b> <para>-or-</para> <paramref name="contents"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void AppendAllLines(string path, IEnumerable<string> contents)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (contents == null)
|
|
|
throw new ArgumentNullException("contents");
|
|
|
|
|
|
@@ -813,8 +924,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="contents">The lines to append to the file.</param>
|
|
|
/// <param name="encoding">The character encoding to use.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="contents"/> is <b>null</b>. <para>-or-</para> <paramref name="encoding"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (contents == null)
|
|
|
throw new ArgumentNullException("contents");
|
|
|
|
|
|
@@ -834,6 +948,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to append the specified string to.</param>
|
|
|
/// <param name="contents">The string to append to the file.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="contents"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void AppendAllText(string path, string contents)
|
|
|
{
|
|
|
using (var stream = this.AppendText(path))
|
|
|
@@ -850,6 +965,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="contents">The string to append to the file.</param>
|
|
|
/// <param name="encoding">The character encoding to use.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="contents"/> is <b>null</b>. <para>-or-</para> <paramref name="encoding"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void AppendAllText(string path, string contents, Encoding encoding)
|
|
|
{
|
|
|
using (var stream = this.AppendText(path, encoding))
|
|
|
@@ -864,6 +980,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The path to the file to append to.</param>
|
|
|
/// <returns>A StreamWriter that appends UTF-8 encoded text to an existing file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public StreamWriter AppendText(string path)
|
|
|
{
|
|
|
return this.AppendText(path, Encoding.UTF8);
|
|
|
@@ -878,8 +995,11 @@ namespace Renci.SshNet
|
|
|
/// A StreamWriter that appends UTF-8 encoded text to an existing file.
|
|
|
/// </returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>. <para>-or-</para> <paramref name="encoding"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public StreamWriter AppendText(string path, Encoding encoding)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (encoding == null)
|
|
|
throw new ArgumentNullException("encoding");
|
|
|
|
|
|
@@ -892,8 +1012,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The path and name of the file to create.</param>
|
|
|
/// <returns>A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileStream Create(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
return new SftpFileStream(this._sftpSession, path, FileMode.Create, FileAccess.ReadWrite);
|
|
|
}
|
|
|
|
|
|
@@ -904,8 +1027,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="bufferSize">The number of bytes buffered for reads and writes to the file.</param>
|
|
|
/// <returns>A <see cref="SftpFileStream"/> that provides read/write access to the file specified in path</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileStream Create(string path, int bufferSize)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
return new SftpFileStream(this._sftpSession, path, FileMode.Create, FileAccess.ReadWrite, bufferSize);
|
|
|
}
|
|
|
|
|
|
@@ -915,9 +1041,10 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to be opened for writing.</param>
|
|
|
/// <returns>A <see cref="System.IO.StreamWriter"/> that writes to the specified file using UTF-8 encoding.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public StreamWriter CreateText(string path)
|
|
|
{
|
|
|
- return new StreamWriter(this.OpenWrite(path), Encoding.UTF8);
|
|
|
+ return CreateText(path, Encoding.UTF8);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -927,8 +1054,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="encoding">The character encoding to use.</param>
|
|
|
/// <returns> A <see cref="System.IO.StreamWriter"/> that writes to the specified file using UTF-8 encoding. </returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public StreamWriter CreateText(string path, Encoding encoding)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
return new StreamWriter(this.OpenWrite(path), encoding);
|
|
|
}
|
|
|
|
|
|
@@ -938,10 +1068,10 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The name of the file or directory to be deleted. Wildcard characters are not supported.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void Delete(string path)
|
|
|
{
|
|
|
var file = this.Get(path);
|
|
|
-
|
|
|
file.Delete();
|
|
|
}
|
|
|
|
|
|
@@ -952,10 +1082,10 @@ namespace Renci.SshNet
|
|
|
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified file or directory was last accessed. This value is expressed in local time.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public DateTime GetLastAccessTime(string path)
|
|
|
{
|
|
|
var file = this.Get(path);
|
|
|
-
|
|
|
return file.LastAccessTime;
|
|
|
}
|
|
|
|
|
|
@@ -966,11 +1096,11 @@ namespace Renci.SshNet
|
|
|
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified file or directory was last accessed. This value is expressed in UTC time.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public DateTime GetLastAccessTimeUtc(string path)
|
|
|
{
|
|
|
- var file = this.Get(path);
|
|
|
-
|
|
|
- return file.LastAccessTime.ToUniversalTime();
|
|
|
+ var lastAccessTime = GetLastAccessTime(path);
|
|
|
+ return lastAccessTime.ToUniversalTime();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -980,10 +1110,10 @@ namespace Renci.SshNet
|
|
|
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified file or directory was last written to. This value is expressed in local time.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public DateTime GetLastWriteTime(string path)
|
|
|
{
|
|
|
var file = this.Get(path);
|
|
|
-
|
|
|
return file.LastWriteTime;
|
|
|
}
|
|
|
|
|
|
@@ -994,11 +1124,11 @@ namespace Renci.SshNet
|
|
|
/// <returns>A <see cref="System.DateTime"/> structure set to the date and time that the specified file or directory was last written to. This value is expressed in UTC time.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
/// <exception cref="SshConnectionException">Client is not connected.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public DateTime GetLastWriteTimeUtc(string path)
|
|
|
{
|
|
|
- var file = this.Get(path);
|
|
|
-
|
|
|
- return file.LastWriteTime.ToUniversalTime();
|
|
|
+ var lastWriteTime = GetLastWriteTime(path);
|
|
|
+ return lastWriteTime.ToUniversalTime();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1008,9 +1138,10 @@ namespace Renci.SshNet
|
|
|
/// <param name="mode">A <see cref="System.IO.FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
|
|
|
/// <returns>An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileStream Open(string path, FileMode mode)
|
|
|
{
|
|
|
- return new SftpFileStream(this._sftpSession, path, mode, FileAccess.ReadWrite);
|
|
|
+ return Open(path, mode, FileAccess.ReadWrite);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1021,8 +1152,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="access">A <see cref="System.IO.FileAccess"/> value that specifies the operations that can be performed on the file.</param>
|
|
|
/// <returns>An unshared <see cref="SftpFileStream"/> that provides access to the specified file, with the specified mode and access.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileStream Open(string path, FileMode mode, FileAccess access)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
return new SftpFileStream(this._sftpSession, path, mode, access);
|
|
|
}
|
|
|
|
|
|
@@ -1032,9 +1166,10 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to be opened for reading.</param>
|
|
|
/// <returns>A read-only System.IO.FileStream on the specified path.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileStream OpenRead(string path)
|
|
|
{
|
|
|
- return new SftpFileStream(this._sftpSession, path, FileMode.Open, FileAccess.Read);
|
|
|
+ return Open(path, FileMode.Open, FileAccess.Read);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1043,6 +1178,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to be opened for reading.</param>
|
|
|
/// <returns>A <see cref="System.IO.StreamReader"/> on the specified path.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public StreamReader OpenText(string path)
|
|
|
{
|
|
|
return new StreamReader(this.OpenRead(path), Encoding.UTF8);
|
|
|
@@ -1054,8 +1190,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to be opened for writing.</param>
|
|
|
/// <returns>An unshared <see cref="SftpFileStream"/> object on the specified path with <see cref="System.IO.FileAccess.Write"/> access.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileStream OpenWrite(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
return new SftpFileStream(this._sftpSession, path, FileMode.OpenOrCreate, FileAccess.Write);
|
|
|
}
|
|
|
|
|
|
@@ -1065,6 +1204,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to open for reading.</param>
|
|
|
/// <returns>A byte array containing the contents of the file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public byte[] ReadAllBytes(string path)
|
|
|
{
|
|
|
using (var stream = this.OpenRead(path))
|
|
|
@@ -1081,6 +1221,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to open for reading.</param>
|
|
|
/// <returns>A string array containing all lines of the file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public string[] ReadAllLines(string path)
|
|
|
{
|
|
|
return this.ReadAllLines(path, Encoding.UTF8);
|
|
|
@@ -1093,6 +1234,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="encoding">The encoding applied to the contents of the file.</param>
|
|
|
/// <returns>A string array containing all lines of the file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public string[] ReadAllLines(string path, Encoding encoding)
|
|
|
{
|
|
|
var lines = new List<string>();
|
|
|
@@ -1112,6 +1254,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to open for reading.</param>
|
|
|
/// <returns>A string containing all lines of the file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public string ReadAllText(string path)
|
|
|
{
|
|
|
return this.ReadAllText(path, Encoding.UTF8);
|
|
|
@@ -1124,6 +1267,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="encoding">The encoding applied to the contents of the file.</param>
|
|
|
/// <returns>A string containing all lines of the file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public string ReadAllText(string path, Encoding encoding)
|
|
|
{
|
|
|
using (var stream = new StreamReader(this.OpenRead(path), encoding))
|
|
|
@@ -1138,6 +1282,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to read.</param>
|
|
|
/// <returns>The lines of the file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public IEnumerable<string> ReadLines(string path)
|
|
|
{
|
|
|
return this.ReadAllLines(path);
|
|
|
@@ -1150,6 +1295,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="encoding">The encoding that is applied to the contents of the file.</param>
|
|
|
/// <returns>The lines of the file.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public IEnumerable<string> ReadLines(string path, Encoding encoding)
|
|
|
{
|
|
|
return this.ReadAllLines(path, encoding);
|
|
|
@@ -1205,6 +1351,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to write to.</param>
|
|
|
/// <param name="bytes">The bytes to write to the file.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void WriteAllBytes(string path, byte[] bytes)
|
|
|
{
|
|
|
using (var stream = this.OpenWrite(path))
|
|
|
@@ -1219,6 +1366,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to write to.</param>
|
|
|
/// <param name="contents">The lines to write to the file.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void WriteAllLines(string path, IEnumerable<string> contents)
|
|
|
{
|
|
|
this.WriteAllLines(path, contents, Encoding.UTF8);
|
|
|
@@ -1230,6 +1378,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to write to.</param>
|
|
|
/// <param name="contents">The string array to write to the file.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void WriteAllLines(string path, string[] contents)
|
|
|
{
|
|
|
this.WriteAllLines(path, contents, Encoding.UTF8);
|
|
|
@@ -1242,6 +1391,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="contents">The lines to write to the file.</param>
|
|
|
/// <param name="encoding">The character encoding to use.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void WriteAllLines(string path, IEnumerable<string> contents, Encoding encoding)
|
|
|
{
|
|
|
using (var stream = this.CreateText(path, encoding))
|
|
|
@@ -1260,6 +1410,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="contents">The string array to write to the file.</param>
|
|
|
/// <param name="encoding">An <see cref="System.Text.Encoding"/> object that represents the character encoding applied to the string array.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void WriteAllLines(string path, string[] contents, Encoding encoding)
|
|
|
{
|
|
|
using (var stream = this.CreateText(path, encoding))
|
|
|
@@ -1277,6 +1428,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The file to write to.</param>
|
|
|
/// <param name="contents">The string to write to the file.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void WriteAllText(string path, string contents)
|
|
|
{
|
|
|
using (var stream = this.CreateText(path))
|
|
|
@@ -1292,6 +1444,7 @@ namespace Renci.SshNet
|
|
|
/// <param name="contents">The string to write to the file.</param>
|
|
|
/// <param name="encoding">The encoding to apply to the string.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void WriteAllText(string path, string contents, Encoding encoding)
|
|
|
{
|
|
|
using (var stream = this.CreateText(path, encoding))
|
|
|
@@ -1306,8 +1459,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The path to the file.</param>
|
|
|
/// <returns>The <see cref="SftpFileAttributes"/> of the file on the path.</returns>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public SftpFileAttributes GetAttributes(string path)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (this._sftpSession == null)
|
|
|
throw new SshConnectionException("Client not connected.");
|
|
|
|
|
|
@@ -1322,8 +1478,11 @@ namespace Renci.SshNet
|
|
|
/// <param name="path">The path to the file.</param>
|
|
|
/// <param name="fileAttributes">The desired <see cref="SftpFileAttributes"/>.</param>
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
|
|
|
+ /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
|
|
|
public void SetAttributes(string path, SftpFileAttributes fileAttributes)
|
|
|
{
|
|
|
+ CheckDisposed();
|
|
|
+
|
|
|
if (this._sftpSession == null)
|
|
|
throw new SshConnectionException("Client not connected.");
|
|
|
|
|
|
@@ -1540,11 +1699,7 @@ namespace Renci.SshNet
|
|
|
base.OnConnected();
|
|
|
|
|
|
this._sftpSession = new SftpSession(this.Session, this.OperationTimeout, this.ConnectionInfo.Encoding);
|
|
|
-
|
|
|
this._sftpSession.Connect();
|
|
|
-
|
|
|
- // Resolve current running version
|
|
|
- this.ProtocolVersion = (int)this._sftpSession.ProtocolVersion;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1554,7 +1709,15 @@ namespace Renci.SshNet
|
|
|
{
|
|
|
base.OnDisconnecting();
|
|
|
|
|
|
- this._sftpSession.Disconnect();
|
|
|
+ // disconnect and dispose the SFTP session
|
|
|
+ // the dispose is necessary since we create a new SFTP session
|
|
|
+ // on each connect
|
|
|
+ if (_sftpSession != null)
|
|
|
+ {
|
|
|
+ this._sftpSession.Disconnect();
|
|
|
+ this._sftpSession.Dispose();
|
|
|
+ this._sftpSession = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1569,9 +1732,6 @@ namespace Renci.SshNet
|
|
|
this._sftpSession = null;
|
|
|
}
|
|
|
|
|
|
- if (this._disposeConnectionInfo)
|
|
|
- ((IDisposable)this.ConnectionInfo).Dispose();
|
|
|
-
|
|
|
base.Dispose(disposing);
|
|
|
}
|
|
|
}
|