Pārlūkot izejas kodu

Remove redundant this qualifiers.
Change SubsystemSession._operationTimeout into a read-only OperationTimeout property.
FlagsAttribute is used as a bit field, so mark it as such.

Gert Driesen 11 gadi atpakaļ
vecāks
revīzija
04d4c18a13

+ 48 - 55
Renci.SshClient/Renci.SshNet/Netconf/NetConfSession.cs

@@ -1,8 +1,8 @@
 using System;
+using System.Globalization;
 using System.Text;
 using System.Threading;
 using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
 using System.Xml;
 using System.Text.RegularExpressions;
 
@@ -10,18 +10,13 @@ namespace Renci.SshNet.NetConf
 {
     internal class NetConfSession : SubsystemSession
     {
-        private readonly StringBuilder _data = new StringBuilder();
+        private const string Prompt = "]]>]]>";
 
+        private readonly StringBuilder _data = new StringBuilder();
         private bool _usingFramingProtocol;
-
-        private const string _prompt = "]]>]]>";
-
         private EventWaitHandle _serverCapabilitiesConfirmed = new AutoResetEvent(false);
-
         private EventWaitHandle _rpcReplyReceived = new AutoResetEvent(false);
-
         private StringBuilder _rpcReply = new StringBuilder();
-
         private int _messageId;
 
         /// <summary>
@@ -56,41 +51,40 @@ namespace Renci.SshNet.NetConf
 
         public XmlDocument SendReceiveRpc(XmlDocument rpc, bool automaticMessageIdHandling)
         {
-            this._data.Clear();
+            _data.Clear();
 
-            XmlNamespaceManager ns = null;
+            XmlNamespaceManager nsMgr = null;
             if (automaticMessageIdHandling)
             {
                 _messageId++;
-                ns = new XmlNamespaceManager(rpc.NameTable);
-                ns.AddNamespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0");
-                rpc.SelectSingleNode("/nc:rpc/@message-id", ns).Value = _messageId.ToString();
+                nsMgr = new XmlNamespaceManager(rpc.NameTable);
+                nsMgr.AddNamespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0");
+                rpc.SelectSingleNode("/nc:rpc/@message-id", nsMgr).Value = _messageId.ToString(CultureInfo.InvariantCulture);
             }
             _rpcReply = new StringBuilder();
             _rpcReplyReceived.Reset();
             var reply = new XmlDocument();
             if (_usingFramingProtocol)
             {
-                StringBuilder command = new StringBuilder(rpc.InnerXml.Length + 10);
+                var command = new StringBuilder(rpc.InnerXml.Length + 10);
                 command.AppendFormat("\n#{0}\n", rpc.InnerXml.Length);
                 command.Append(rpc.InnerXml);
                 command.Append("\n##\n");
-                this.SendData(Encoding.UTF8.GetBytes(command.ToString()));
+                SendData(Encoding.UTF8.GetBytes(command.ToString()));
 
-                this.WaitOnHandle(this._rpcReplyReceived, this._operationTimeout);
+                WaitOnHandle(_rpcReplyReceived, OperationTimeout);
                 reply.LoadXml(_rpcReply.ToString());
             }
             else
             {
-                this.SendData(Encoding.UTF8.GetBytes(rpc.InnerXml + _prompt));
-                this.WaitOnHandle(this._rpcReplyReceived, this._operationTimeout);
+                SendData(Encoding.UTF8.GetBytes(rpc.InnerXml + Prompt));
+                WaitOnHandle(_rpcReplyReceived, OperationTimeout);
                 reply.LoadXml(_rpcReply.ToString());
             }
             if (automaticMessageIdHandling)
             {
-                //string reply_id = rpc.SelectSingleNode("/nc:rpc-reply/@message-id", ns).Value;
-                string reply_id = rpc.SelectSingleNode("/nc:rpc/@message-id", ns).Value;
-                if (reply_id != _messageId.ToString())
+                var replyId = rpc.SelectSingleNode("/nc:rpc/@message-id", nsMgr).Value;
+                if (replyId != _messageId.ToString(CultureInfo.InvariantCulture))
                 {
                     throw new NetConfServerException("The rpc message id does not match the rpc-reply message id.");
                 }
@@ -100,83 +94,82 @@ namespace Renci.SshNet.NetConf
 
         protected override void OnChannelOpen()
         {
-            this._data.Clear();
+            _data.Clear();
 
-            string message = string.Format("{0}{1}", this.ClientCapabilities.InnerXml, _prompt);
+            var message = string.Format("{0}{1}", ClientCapabilities.InnerXml, Prompt);
 
-            this.SendData(Encoding.UTF8.GetBytes(message));
+            SendData(Encoding.UTF8.GetBytes(message));
 
-            this.WaitOnHandle(this._serverCapabilitiesConfirmed, this._operationTimeout);
+            WaitOnHandle(_serverCapabilitiesConfirmed, OperationTimeout);
         }
 
         protected override void OnDataReceived(uint dataTypeCode, byte[] data)
         {
-            string chunk = Encoding.UTF8.GetString(data);
+            var chunk = Encoding.UTF8.GetString(data);
 
-            if (this.ServerCapabilities == null)   // This must be server capabilities, old protocol
+            if (ServerCapabilities == null)   // This must be server capabilities, old protocol
             {
-                this._data.Append(chunk);  
+                _data.Append(chunk);  
 
-                if (!chunk.Contains(_prompt))
+                if (!chunk.Contains(Prompt))
                 {
                     return;
                 }
                 try
                 {
-                    chunk = this._data.ToString(); 
-                    this._data.Clear();
+                    chunk = _data.ToString(); 
+                    _data.Clear();
 
-                    this.ServerCapabilities = new XmlDocument();
-                    this.ServerCapabilities.LoadXml(chunk.Replace(_prompt, ""));
+                    ServerCapabilities = new XmlDocument();
+                    ServerCapabilities.LoadXml(chunk.Replace(Prompt, ""));
                 }
                 catch (XmlException e)
                 {
                     throw new NetConfServerException("Server capabilities received are not well formed XML", e);
                 }
 
-                XmlNamespaceManager ns = new XmlNamespaceManager(this.ServerCapabilities.NameTable);
-
-                ns.AddNamespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0");
+                var nsMgr = new XmlNamespaceManager(ServerCapabilities.NameTable);
+                nsMgr.AddNamespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0");
 
-                this._usingFramingProtocol = (this.ServerCapabilities.SelectSingleNode("/nc:hello/nc:capabilities/nc:capability[text()='urn:ietf:params:netconf:base:1.1']", ns) != null);
+                _usingFramingProtocol = (ServerCapabilities.SelectSingleNode("/nc:hello/nc:capabilities/nc:capability[text()='urn:ietf:params:netconf:base:1.1']", nsMgr) != null);
 
-                this._serverCapabilitiesConfirmed.Set();
+                _serverCapabilitiesConfirmed.Set();
             }
-            else if (this._usingFramingProtocol)
+            else if (_usingFramingProtocol)
             {
                 int position = 0;
 
                 for (; ; )
                 {
-                    Match match = Regex.Match(chunk.Substring(position), @"\n#(?<length>\d+)\n");
+                    var match = Regex.Match(chunk.Substring(position), @"\n#(?<length>\d+)\n");
                     if (!match.Success)
                     {
                         break;
                     }
-                    int fractionLength = Convert.ToInt32(match.Groups["length"].Value);
-                    this._rpcReply.Append(chunk, position + match.Index + match.Length, fractionLength);
+                    var fractionLength = Convert.ToInt32(match.Groups["length"].Value);
+                    _rpcReply.Append(chunk, position + match.Index + match.Length, fractionLength);
                     position += match.Index + match.Length + fractionLength;
                 }
                 if (Regex.IsMatch(chunk.Substring(position), @"\n##\n"))
                 {
-                    this._rpcReplyReceived.Set();
+                    _rpcReplyReceived.Set();
                 }
             }
             else  // Old protocol
             {
-                this._data.Append(chunk);
+                _data.Append(chunk);
 
-                if (!chunk.Contains(_prompt))
+                if (!chunk.Contains(Prompt))
                 {
                     return;
                     //throw new NetConfServerException("Server XML message does not end with the prompt " + _prompt);
                 }
                 
-                chunk = this._data.ToString();
-                this._data.Clear();
+                chunk = _data.ToString();
+                _data.Clear();
 
-                this._rpcReply.Append(chunk.Replace(_prompt, ""));
-                this._rpcReplyReceived.Set();
+                _rpcReply.Append(chunk.Replace(Prompt, ""));
+                _rpcReplyReceived.Set();
             }
         }
 
@@ -186,16 +179,16 @@ namespace Renci.SshNet.NetConf
 
             if (disposing)
             {
-                if (this._serverCapabilitiesConfirmed != null)
+                if (_serverCapabilitiesConfirmed != null)
                 {
-                    this._serverCapabilitiesConfirmed.Dispose();
-                    this._serverCapabilitiesConfirmed = null;
+                    _serverCapabilitiesConfirmed.Dispose();
+                    _serverCapabilitiesConfirmed = null;
                 }
 
-                if (this._rpcReplyReceived != null)
+                if (_rpcReplyReceived != null)
                 {
-                    this._rpcReplyReceived.Dispose();
-                    this._rpcReplyReceived = null;
+                    _rpcReplyReceived.Dispose();
+                    _rpcReplyReceived = null;
                 }
             }
         }

+ 4 - 1
Renci.SshClient/Renci.SshNet/Sftp/Flags.cs

@@ -1,5 +1,8 @@
-namespace Renci.SshNet.Sftp
+using System;
+
+namespace Renci.SshNet.Sftp
 {
+    [Flags]
     internal enum Flags
     {
         None = 0x00000000,

+ 177 - 177
Renci.SshClient/Renci.SshNet/Sftp/SftpFileStream.cs

@@ -43,7 +43,7 @@ namespace Renci.SshNet.Sftp
         {
             get
             {
-                return ((this._access & FileAccess.Read) != 0);
+                return ((_access & FileAccess.Read) != 0);
             }
         }
 
@@ -55,7 +55,7 @@ namespace Renci.SshNet.Sftp
         {
             get
             {
-                return this._canSeek;
+                return _canSeek;
             }
         }
 
@@ -67,7 +67,7 @@ namespace Renci.SshNet.Sftp
         {
             get
             {
-                return ((this._access & FileAccess.Write) != 0);
+                return ((_access & FileAccess.Write) != 0);
             }
         }
 
@@ -84,15 +84,15 @@ namespace Renci.SshNet.Sftp
             get
             {
                 // Validate that the object can actually do this.
-                if (!this._canSeek)
+                if (!_canSeek)
                 {
                     throw new NotSupportedException("Seek operation is not supported.");
                 }
 
                 // Lock down the file stream while we do this.
-                lock (this._lock)
+                lock (_lock)
                 {
-                    if (this._handle == null)
+                    if (_handle == null)
                     {
                         // ECMA says this should be IOException even though
                         // everywhere else uses ObjectDisposedException.
@@ -101,17 +101,17 @@ namespace Renci.SshNet.Sftp
 
                     // Flush the write buffer, because it may
                     // affect the length of the stream.
-                    if (this._bufferOwnedByWrite)
+                    if (_bufferOwnedByWrite)
                     {
-                        this.FlushWriteBuffer();
+                        FlushWriteBuffer();
                     }
 
                     //  Update file attributes
-                    this._attributes = this._session.RequestFStat(this._handle);
+                    _attributes = _session.RequestFStat(_handle);
 
-                    if (this._attributes != null && this._attributes.Size > -1)
+                    if (_attributes != null && _attributes.Size > -1)
                     {
-                        return this._attributes.Size;
+                        return _attributes.Size;
                     }
                     throw new IOException("Seek operation failed.");
                 }
@@ -132,15 +132,15 @@ namespace Renci.SshNet.Sftp
         {
             get
             {
-                if (!this._canSeek)
+                if (!_canSeek)
                 {
                     throw new NotSupportedException("Seek operation not supported.");
                 }
-                return this._position;
+                return _position;
             }
             set
             {
-                this.Seek(value, SeekOrigin.Begin);
+                Seek(value, SeekOrigin.Begin);
             }
         }
 
@@ -154,7 +154,7 @@ namespace Renci.SshNet.Sftp
         {
             get
             {
-                return this._isAsync;
+                return _isAsync;
             }
         }
 
@@ -170,8 +170,8 @@ namespace Renci.SshNet.Sftp
         {
             get
             {
-                this.Flush();
-                return this._handle;
+                Flush();
+                return _handle;
             }
         }
 
@@ -225,21 +225,21 @@ namespace Renci.SshNet.Sftp
                 throw new ArgumentOutOfRangeException("mode");
             }
 
-            this.Timeout = TimeSpan.FromSeconds(30);
-            this.Name = path;
+            Timeout = TimeSpan.FromSeconds(30);
+            Name = path;
 
             // Initialize the object state.
-            this._session = session;
-            this._access = access;
-            this._ownsHandle = true;
-            this._isAsync = useAsync;
-            this._bufferPosition = 0;
-            this._bufferLen = 0;
-            this._bufferOwnedByWrite = false;
-            this._canSeek = true;
-            this._position = 0;
-            this._serverFilePosition = 0;
-            this._session.Disconnected += Session_Disconnected;
+            _session = session;
+            _access = access;
+            _ownsHandle = true;
+            _isAsync = useAsync;
+            _bufferPosition = 0;
+            _bufferLen = 0;
+            _bufferOwnedByWrite = false;
+            _canSeek = true;
+            _position = 0;
+            _serverFilePosition = 0;
+            _session.Disconnected += Session_Disconnected;
 
             var flags = Flags.None;
 
@@ -263,8 +263,8 @@ namespace Renci.SshNet.Sftp
                     flags |= Flags.Append;
                     break;
                 case FileMode.Create:
-                    this._handle = this._session.RequestOpen(path, flags | Flags.Truncate, true);
-                    if (this._handle == null)
+                    _handle = _session.RequestOpen(path, flags | Flags.Truncate, true);
+                    if (_handle == null)
                     {
                         flags |= Flags.CreateNew;
                     }
@@ -286,20 +286,20 @@ namespace Renci.SshNet.Sftp
                     break;
             }
 
-            if (this._handle == null)
-                this._handle = this._session.RequestOpen(path, flags);
+            if (_handle == null)
+                _handle = _session.RequestOpen(path, flags);
 
-            this._attributes = this._session.RequestFStat(this._handle);
+            _attributes = _session.RequestFStat(_handle);
 
-            this._readBufferSize = (int)session.CalculateOptimalReadLength((uint)bufferSize);
-            this._readBuffer = new byte[_readBufferSize];
-            this._writeBufferSize = (int)session.CalculateOptimalWriteLength((uint)bufferSize, _handle);
-            this._writeBuffer = new byte[_writeBufferSize];
+            _readBufferSize = (int)session.CalculateOptimalReadLength((uint)bufferSize);
+            _readBuffer = new byte[_readBufferSize];
+            _writeBufferSize = (int)session.CalculateOptimalWriteLength((uint)bufferSize, _handle);
+            _writeBuffer = new byte[_writeBufferSize];
 
             if (mode == FileMode.Append)
             {
-                this._position = this._attributes.Size;
-                this._serverFilePosition = (ulong)this._attributes.Size;
+                _position = _attributes.Size;
+                _serverFilePosition = (ulong)_attributes.Size;
             }
         }
 
@@ -309,7 +309,7 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         ~SftpFileStream()
         {
-            this.Dispose(false);
+            Dispose(false);
         }
 
         /// <summary>
@@ -317,7 +317,7 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         public override void Close()
         {
-            this.Dispose(true);
+            Dispose(true);
             GC.SuppressFinalize(this);
         }
 
@@ -328,17 +328,17 @@ namespace Renci.SshNet.Sftp
         /// <exception cref="ObjectDisposedException">Stream is closed.</exception>
         public override void Flush()
         {
-            lock (this._lock)
+            lock (_lock)
             {
-                if (this._handle != null)
+                if (_handle != null)
                 {
-                    if (this._bufferOwnedByWrite)
+                    if (_bufferOwnedByWrite)
                     {
-                        this.FlushWriteBuffer();
+                        FlushWriteBuffer();
                     }
                     else
                     {
-                        this.FlushReadBuffer();
+                        FlushReadBuffer();
                     }
                 }
                 else
@@ -377,38 +377,38 @@ namespace Renci.SshNet.Sftp
                 throw new ArgumentException("Invalid array range.");
 
             // Lock down the file stream while we do this.
-            lock (this._lock)
+            lock (_lock)
             {
                 // Set up for the read operation.
-                this.SetupRead();
+                SetupRead();
 
                 // Read data into the caller's buffer.
                 while (count > 0)
                 {
                     // How much data do we have available in the buffer?
-                    var tempLen = this._bufferLen - this._bufferPosition;
+                    var tempLen = _bufferLen - _bufferPosition;
                     if (tempLen <= 0)
                     {
-                        this._bufferPosition = 0;
+                        _bufferPosition = 0;
 
-                        var data = this._session.RequestRead(this._handle, (ulong)this._position, (uint)this._readBufferSize);
+                        var data = _session.RequestRead(_handle, (ulong)_position, (uint)_readBufferSize);
 
-                        this._bufferLen = data.Length;
+                        _bufferLen = data.Length;
 
-                        Buffer.BlockCopy(data, 0, this._readBuffer, 0, this._bufferLen);
-                        this._serverFilePosition = (ulong)this._position;
+                        Buffer.BlockCopy(data, 0, _readBuffer, 0, _bufferLen);
+                        _serverFilePosition = (ulong)_position;
 
-                        if (this._bufferLen < 0)
+                        if (_bufferLen < 0)
                         {
-                            this._bufferLen = 0;
+                            _bufferLen = 0;
                             //  TODO:   Add SFTP error code or message if possible
                             throw new IOException("Read operation failed.");
                         }
-                        if (this._bufferLen == 0)
+                        if (_bufferLen == 0)
                         {
                             break;
                         }
-                        tempLen = this._bufferLen;
+                        tempLen = _bufferLen;
                     }
 
                     // Don't read more than the caller wants.
@@ -418,14 +418,14 @@ namespace Renci.SshNet.Sftp
                     }
 
                     // Copy stream data to the caller's buffer.
-                    Buffer.BlockCopy(this._readBuffer, this._bufferPosition, buffer, offset, tempLen);
+                    Buffer.BlockCopy(_readBuffer, _bufferPosition, buffer, offset, tempLen);
 
                     // Advance to the next buffer positions.
                     readLen += tempLen;
                     offset += tempLen;
                     count -= tempLen;
-                    this._bufferPosition += tempLen;
-                    this._position += tempLen;
+                    _bufferPosition += tempLen;
+                    _position += tempLen;
                 }
             }
 
@@ -445,29 +445,29 @@ namespace Renci.SshNet.Sftp
         public override int ReadByte()
         {
             // Lock down the file stream while we do this.
-            lock (this._lock)
+            lock (_lock)
             {
                 // Setup the object for reading.
-                this.SetupRead();
+                SetupRead();
 
                 // Read more data into the internal buffer if necessary.
-                if (this._bufferPosition >= this._bufferLen)
+                if (_bufferPosition >= _bufferLen)
                 {
-                    this._bufferPosition = 0;
+                    _bufferPosition = 0;
 
-                    var data = this._session.RequestRead(this._handle, (ulong)this._position, (uint)this._readBufferSize);
+                    var data = _session.RequestRead(_handle, (ulong)_position, (uint)_readBufferSize);
 
-                    this._bufferLen = data.Length;
-                    Buffer.BlockCopy(data, 0, this._readBuffer, 0, this._readBufferSize);
-                    this._serverFilePosition = (ulong)this._position;
+                    _bufferLen = data.Length;
+                    Buffer.BlockCopy(data, 0, _readBuffer, 0, _readBufferSize);
+                    _serverFilePosition = (ulong)_position;
 
-                    if (this._bufferLen < 0)
+                    if (_bufferLen < 0)
                     {
-                        this._bufferLen = 0;
+                        _bufferLen = 0;
                         //  TODO:   Add SFTP error code or message if possible
                         throw new IOException("Read operation failed.");
                     }
-                    if (this._bufferLen == 0)
+                    if (_bufferLen == 0)
                     {
                         // We've reached EOF.
                         return -1;
@@ -475,8 +475,8 @@ namespace Renci.SshNet.Sftp
                 }
 
                 // Extract the next byte from the buffer.
-                ++this._position;
-                return this._readBuffer[this._bufferPosition++];
+                ++_position;
+                return _readBuffer[_bufferPosition++];
             }
         }
 
@@ -496,37 +496,37 @@ namespace Renci.SshNet.Sftp
             long newPosn = -1;
 
             // Bail out if this stream is not capable of seeking.
-            if (!this._canSeek)
+            if (!_canSeek)
             {
                 throw new NotSupportedException("Seek is not supported.");
             }
 
             // Lock down the file stream while we do this.
-            lock (this._lock)
+            lock (_lock)
             {
                 // Bail out if the handle is invalid.
-                if (this._handle == null)
+                if (_handle == null)
                 {
                     throw new ObjectDisposedException("Stream is closed.");
                 }
 
                 // Don't do anything if the position won't be moving.
-                if (origin == SeekOrigin.Begin && offset == this._position)
+                if (origin == SeekOrigin.Begin && offset == _position)
                 {
                     return offset;
                 }
                 if (origin == SeekOrigin.Current && offset == 0)
                 {
-                    return this._position;
+                    return _position;
                 }
 
-                this._attributes = this._session.RequestFStat(this._handle);
+                _attributes = _session.RequestFStat(_handle);
 
                 // The behaviour depends upon the read/write mode.
-                if (this._bufferOwnedByWrite)
+                if (_bufferOwnedByWrite)
                 {
                     // Flush the write buffer and then seek.
-                    this.FlushWriteBuffer();
+                    FlushWriteBuffer();
 
                     switch (origin)
                     {
@@ -534,10 +534,10 @@ namespace Renci.SshNet.Sftp
                             newPosn = offset;
                             break;
                         case SeekOrigin.Current:
-                            newPosn = this._position + offset;
+                            newPosn = _position + offset;
                             break;
                         case SeekOrigin.End:
-                            newPosn = this._attributes.Size - offset;
+                            newPosn = _attributes.Size - offset;
                             break;
                     }
 
@@ -545,8 +545,8 @@ namespace Renci.SshNet.Sftp
                     {
                         throw new EndOfStreamException("End of stream.");
                     }
-                    this._position = newPosn;
-                    this._serverFilePosition = (ulong)newPosn;
+                    _position = newPosn;
+                    _serverFilePosition = (ulong)newPosn;
                 }
                 else
                 {
@@ -554,31 +554,31 @@ namespace Renci.SshNet.Sftp
                     // the current read buffer bounds.
                     if (origin == SeekOrigin.Begin)
                     {
-                        newPosn = this._position - this._bufferPosition;
+                        newPosn = _position - _bufferPosition;
                         if (offset >= newPosn && offset <
-                                (newPosn + this._bufferLen))
+                                (newPosn + _bufferLen))
                         {
-                            this._bufferPosition = (int)(offset - newPosn);
-                            this._position = offset;
-                            return this._position;
+                            _bufferPosition = (int)(offset - newPosn);
+                            _position = offset;
+                            return _position;
                         }
                     }
                     else if (origin == SeekOrigin.Current)
                     {
-                        newPosn = this._position + offset;
-                        if (newPosn >= (this._position - this._bufferPosition) &&
-                           newPosn < (this._position - this._bufferPosition + this._bufferLen))
+                        newPosn = _position + offset;
+                        if (newPosn >= (_position - _bufferPosition) &&
+                           newPosn < (_position - _bufferPosition + _bufferLen))
                         {
-                            this._bufferPosition =
-                                (int)(newPosn - (this._position - this._bufferPosition));
-                            this._position = newPosn;
-                            return this._position;
+                            _bufferPosition =
+                                (int)(newPosn - (_position - _bufferPosition));
+                            _position = newPosn;
+                            return _position;
                         }
                     }
 
                     // Abandon the read buffer.
-                    this._bufferPosition = 0;
-                    this._bufferLen = 0;
+                    _bufferPosition = 0;
+                    _bufferLen = 0;
 
                     // Seek to the new position.
                     switch (origin)
@@ -587,10 +587,10 @@ namespace Renci.SshNet.Sftp
                             newPosn = offset;
                             break;
                         case SeekOrigin.Current:
-                            newPosn = this._position + offset;
+                            newPosn = _position + offset;
                             break;
                         case SeekOrigin.End:
-                            newPosn = this._attributes.Size - offset;
+                            newPosn = _attributes.Size - offset;
                             break;
                     }
 
@@ -599,9 +599,9 @@ namespace Renci.SshNet.Sftp
                         throw new EndOfStreamException();
                     }
 
-                    this._position = newPosn;
+                    _position = newPosn;
                 }
-                return this._position;
+                return _position;
             }
         }
 
@@ -620,20 +620,20 @@ namespace Renci.SshNet.Sftp
             {
                 throw new ArgumentOutOfRangeException("value");
             }
-            if (!this._canSeek)
+            if (!_canSeek)
             {
                 throw new NotSupportedException("Seek is not supported.");
             }
 
             // Lock down the file stream while we do this.
-            lock (this._lock)
+            lock (_lock)
             {
                 // Setup this object for writing.
-                this.SetupWrite();
+                SetupWrite();
 
-                this._attributes.Size = value;
+                _attributes.Size = value;
 
-                this._session.RequestFSetStat(this._handle, this._attributes);
+                _session.RequestFSetStat(_handle, _attributes);
             }
         }
 
@@ -661,30 +661,30 @@ namespace Renci.SshNet.Sftp
                 throw new ArgumentException("Invalid array range.");
 
             // Lock down the file stream while we do this.
-            lock (this._lock)
+            lock (_lock)
             {
                 // Setup this object for writing.
-                this.SetupWrite();
+                SetupWrite();
 
                 // Write data to the file stream.
                 while (count > 0)
                 {
                     // Determine how many bytes we can write to the buffer.
-                    var tempLen = this._writeBufferSize - this._bufferPosition;
+                    var tempLen = _writeBufferSize - _bufferPosition;
                     if (tempLen <= 0)
                     {
-                        var data = new byte[this._bufferPosition];
+                        var data = new byte[_bufferPosition];
 
-                        Buffer.BlockCopy(this._writeBuffer, 0, data, 0, this._bufferPosition);
+                        Buffer.BlockCopy(_writeBuffer, 0, data, 0, _bufferPosition);
 
                         using (var wait = new AutoResetEvent(false))
                         {
-                            this._session.RequestWrite(this._handle, this._serverFilePosition, data, wait);
-                            this._serverFilePosition += (ulong)data.Length;
+                            _session.RequestWrite(_handle, _serverFilePosition, data, wait);
+                            _serverFilePosition += (ulong)data.Length;
                         }
 
-                        this._bufferPosition = 0;
-                        tempLen = this._writeBufferSize;
+                        _bufferPosition = 0;
+                        tempLen = _writeBufferSize;
                     }
                     if (tempLen > count)
                     {
@@ -692,7 +692,7 @@ namespace Renci.SshNet.Sftp
                     }
 
                     // Can we short-cut the internal buffer?
-                    if (this._bufferPosition == 0 && tempLen == this._writeBufferSize)
+                    if (_bufferPosition == 0 && tempLen == _writeBufferSize)
                     {
                         // Yes: write the data directly to the file.
                         var data = new byte[tempLen];
@@ -701,38 +701,38 @@ namespace Renci.SshNet.Sftp
 
                         using (var wait = new AutoResetEvent(false))
                         {
-                            this._session.RequestWrite(this._handle, this._serverFilePosition, data, wait);
-                            this._serverFilePosition += (ulong)data.Length;
+                            _session.RequestWrite(_handle, _serverFilePosition, data, wait);
+                            _serverFilePosition += (ulong)data.Length;
                         }
                     }
                     else
                     {
                         // No: copy the data to the write buffer first.
-                        Buffer.BlockCopy(buffer, offset, _writeBuffer, this._bufferPosition, tempLen);
-                        this._bufferPosition += tempLen;
+                        Buffer.BlockCopy(buffer, offset, _writeBuffer, _bufferPosition, tempLen);
+                        _bufferPosition += tempLen;
                     }
 
                     // Advance the buffer and stream positions.
-                    this._position += tempLen;
+                    _position += tempLen;
                     offset += tempLen;
                     count -= tempLen;
                 }
 
                 // If the buffer is full, then do a speculative flush now,
                 // rather than waiting for the next call to this method.
-                if (this._bufferPosition >= _writeBufferSize)
+                if (_bufferPosition >= _writeBufferSize)
                 {
-                    var data = new byte[this._bufferPosition];
+                    var data = new byte[_bufferPosition];
 
-                    Buffer.BlockCopy(this._writeBuffer, 0, data, 0, this._bufferPosition);
+                    Buffer.BlockCopy(_writeBuffer, 0, data, 0, _bufferPosition);
 
                     using (var wait = new AutoResetEvent(false))
                     {
-                        this._session.RequestWrite(this._handle, this._serverFilePosition, data, wait);
-                        this._serverFilePosition += (ulong)data.Length;
+                        _session.RequestWrite(_handle, _serverFilePosition, data, wait);
+                        _serverFilePosition += (ulong)data.Length;
                     }
 
-                    this._bufferPosition = 0;
+                    _bufferPosition = 0;
                 }
             }
         }
@@ -747,30 +747,30 @@ namespace Renci.SshNet.Sftp
         public override void WriteByte(byte value)
         {
             // Lock down the file stream while we do this.
-            lock (this._lock)
+            lock (_lock)
             {
                 // Setup the object for writing.
-                this.SetupWrite();
+                SetupWrite();
 
                 // Flush the current buffer if it is full.
-                if (this._bufferPosition >= this._writeBufferSize)
+                if (_bufferPosition >= _writeBufferSize)
                 {
-                    var data = new byte[this._bufferPosition];
+                    var data = new byte[_bufferPosition];
 
-                    Buffer.BlockCopy(this._writeBuffer, 0, data, 0, this._bufferPosition);
+                    Buffer.BlockCopy(_writeBuffer, 0, data, 0, _bufferPosition);
 
                     using (var wait = new AutoResetEvent(false))
                     {
-                        this._session.RequestWrite(this._handle, this._serverFilePosition, data, wait);
-                        this._serverFilePosition += (ulong)data.Length;
+                        _session.RequestWrite(_handle, _serverFilePosition, data, wait);
+                        _serverFilePosition += (ulong)data.Length;
                     }
 
-                    this._bufferPosition = 0;
+                    _bufferPosition = 0;
                 }
 
                 // Write the byte into the buffer and advance the posn.
-                _writeBuffer[this._bufferPosition++] = value;
-                ++this._position;
+                _writeBuffer[_bufferPosition++] = value;
+                ++_position;
             }
         }
 
@@ -782,29 +782,29 @@ namespace Renci.SshNet.Sftp
         {
             base.Dispose(disposing);
 
-            if (this._session != null)
+            if (_session != null)
             {
-                lock (this._lock)
+                lock (_lock)
                 {
-                    if (this._session != null)
+                    if (_session != null)
                     {
-                        if (this._handle != null)
+                        if (_handle != null)
                         {
-                            if (this._bufferOwnedByWrite)
+                            if (_bufferOwnedByWrite)
                             {
-                                this.FlushWriteBuffer();
+                                FlushWriteBuffer();
                             }
 
-                            if (this._ownsHandle)
+                            if (_ownsHandle)
                             {
-                                this._session.RequestClose(this._handle);
+                                _session.RequestClose(_handle);
                             }
 
-                            this._handle = null;
+                            _handle = null;
                         }
 
-                        this._session.Disconnected -= Session_Disconnected;
-                        this._session = null;
+                        _session.Disconnected -= Session_Disconnected;
+                        _session = null;
                     }
                 }
             }
@@ -815,14 +815,14 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         private void FlushReadBuffer()
         {
-            if (this._canSeek)
+            if (_canSeek)
             {
-                if (this._bufferPosition < this._bufferLen)
+                if (_bufferPosition < _bufferLen)
                 {
-                    this._position -= this._bufferPosition;
+                    _position -= _bufferPosition;
                 }
-                this._bufferPosition = 0;
-                this._bufferLen = 0;
+                _bufferPosition = 0;
+                _bufferLen = 0;
             }
         }
 
@@ -831,19 +831,19 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         private void FlushWriteBuffer()
         {
-            if (this._bufferPosition > 0)
+            if (_bufferPosition > 0)
             {
-                var data = new byte[this._bufferPosition];
+                var data = new byte[_bufferPosition];
 
-                Buffer.BlockCopy(this._writeBuffer, 0, data, 0, this._bufferPosition);
+                Buffer.BlockCopy(_writeBuffer, 0, data, 0, _bufferPosition);
 
                 using (var wait = new AutoResetEvent(false))
                 {
-                    this._session.RequestWrite(this._handle, this._serverFilePosition, data, wait);
-                    this._serverFilePosition += (ulong)data.Length;
+                    _session.RequestWrite(_handle, _serverFilePosition, data, wait);
+                    _serverFilePosition += (ulong)data.Length;
                 }
 
-                this._bufferPosition = 0;
+                _bufferPosition = 0;
             }
         }
 
@@ -852,18 +852,18 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         private void SetupRead()
         {
-            if ((this._access & FileAccess.Read) == 0)
+            if ((_access & FileAccess.Read) == 0)
             {
                 throw new NotSupportedException("Read not supported.");
             }
-            if (this._handle == null)
+            if (_handle == null)
             {
                 throw new ObjectDisposedException("Stream is closed.");
             }
-            if (this._bufferOwnedByWrite)
+            if (_bufferOwnedByWrite)
             {
-                this.FlushWriteBuffer();
-                this._bufferOwnedByWrite = false;
+                FlushWriteBuffer();
+                _bufferOwnedByWrite = false;
             }
         }
 
@@ -872,27 +872,27 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         private void SetupWrite()
         {
-            if ((this._access & FileAccess.Write) == 0)
+            if ((_access & FileAccess.Write) == 0)
             {
                 throw new NotSupportedException("Write not supported.");
             }
-            if (this._handle == null)
+            if (_handle == null)
             {
                 throw new ObjectDisposedException("Stream is closed.");
             }
-            if (!this._bufferOwnedByWrite)
+            if (!_bufferOwnedByWrite)
             {
-                this.FlushReadBuffer();
-                this._bufferOwnedByWrite = true;
+                FlushReadBuffer();
+                _bufferOwnedByWrite = true;
             }
         }
 
         private void Session_Disconnected(object sender, EventArgs e)
         {
-            lock (this._lock)
+            lock (_lock)
             {
-                this._session.Disconnected -= Session_Disconnected;
-                this._session = null;
+                _session.Disconnected -= Session_Disconnected;
+                _session = null;
             }
         }
     }

+ 298 - 305
Renci.SshClient/Renci.SshNet/Sftp/SftpSession.cs

@@ -2,7 +2,6 @@
 using System.Linq;
 using System.Text;
 using System.Threading;
-using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 using System.Collections.Generic;
 using System.Globalization;
@@ -13,9 +12,9 @@ namespace Renci.SshNet.Sftp
 {
     internal class SftpSession : SubsystemSession
     {
-        private const int MAXIMUM_SUPPORTED_VERSION = 3;
+        private const int MaximumSupportedVersion = 3;
 
-        private const int MINIMUM_SUPPORTED_VERSION = 0;
+        private const int MinimumSupportedVersion = 0;
 
         private readonly Dictionary<uint, SftpRequest> _requests = new Dictionary<uint, SftpRequest>();
 
@@ -51,7 +50,7 @@ namespace Renci.SshNet.Sftp
 
                 return (uint)this._requestId;
 #else
-                return ((uint)Interlocked.Increment(ref this._requestId));
+                return ((uint)Interlocked.Increment(ref _requestId));
 #endif
             }
         }
@@ -63,13 +62,13 @@ namespace Renci.SshNet.Sftp
 
         public void ChangeDirectory(string path)
         {
-            var fullPath = this.GetCanonicalPath(path);
+            var fullPath = GetCanonicalPath(path);
 
-            var handle = this.RequestOpenDir(fullPath);
+            var handle = RequestOpenDir(fullPath);
 
-            this.RequestClose(handle);
+            RequestClose(handle);
 
-            this.WorkingDirectory = fullPath;
+            WorkingDirectory = fullPath;
         }
 
         internal void SendMessage(SftpMessage sftpMessage)
@@ -81,7 +80,7 @@ namespace Renci.SshNet.Sftp
             ((uint)messageData.Length).GetBytes().CopyTo(data, 0);
             messageData.CopyTo(data, 4);
 
-            this.SendData(data);
+            SendData(data);
         }
 
         /// <summary>
@@ -95,7 +94,7 @@ namespace Renci.SshNet.Sftp
 
             var canonizedPath = string.Empty;
 
-            var realPathFiles = this.RequestRealPath(fullPath, true);
+            var realPathFiles = RequestRealPath(fullPath, true);
 
             if (realPathFiles != null)
             {
@@ -112,14 +111,14 @@ namespace Renci.SshNet.Sftp
                 fullPath.IndexOf('/') < 0)
                 return fullPath;
 
-            var pathParts = fullPath.Split(new char[] { '/' });
+            var pathParts = fullPath.Split(new[] { '/' });
 
             var partialFullPath = string.Join("/", pathParts, 0, pathParts.Length - 1);
 
             if (string.IsNullOrEmpty(partialFullPath))
                 partialFullPath = "/";
 
-            realPathFiles = this.RequestRealPath(partialFullPath, true);
+            realPathFiles = RequestRealPath(partialFullPath, true);
 
             if (realPathFiles != null)
             {
@@ -141,15 +140,15 @@ namespace Renci.SshNet.Sftp
         {
             var fullPath = path;
 
-            if (!string.IsNullOrEmpty(path) && path[0] != '/' && this.WorkingDirectory != null)
+            if (!string.IsNullOrEmpty(path) && path[0] != '/' && WorkingDirectory != null)
             {
-                if (this.WorkingDirectory[this.WorkingDirectory.Length - 1] == '/')
+                if (WorkingDirectory[WorkingDirectory.Length - 1] == '/')
                 {
-                    fullPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}", this.WorkingDirectory, path);
+                    fullPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}", WorkingDirectory, path);
                 }
                 else
                 {
-                    fullPath = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", this.WorkingDirectory, path);
+                    fullPath = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", WorkingDirectory, path);
                 }
             }
             return fullPath;
@@ -157,67 +156,67 @@ namespace Renci.SshNet.Sftp
 
         protected override void OnChannelOpen()
         {
-            this.SendMessage(new SftpInitRequest(MAXIMUM_SUPPORTED_VERSION));
+            SendMessage(new SftpInitRequest(MaximumSupportedVersion));
 
-            this.WaitOnHandle(this._sftpVersionConfirmed, this._operationTimeout);
+            WaitOnHandle(_sftpVersionConfirmed, OperationTimeout);
 
-            if (this.ProtocolVersion > MAXIMUM_SUPPORTED_VERSION || this.ProtocolVersion < MINIMUM_SUPPORTED_VERSION)
+            if (ProtocolVersion > MaximumSupportedVersion || ProtocolVersion < MinimumSupportedVersion)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Server SFTP version {0} is not supported.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Server SFTP version {0} is not supported.", ProtocolVersion));
             }
 
             //  Resolve current directory
-            this.WorkingDirectory = this.RequestRealPath(".").First().Key;
+            WorkingDirectory = RequestRealPath(".").First().Key;
         }
 
         protected override void OnDataReceived(uint dataTypeCode, byte[] data)
         {
             //  Add channel data to internal data holder
-            this._data.AddRange(data);
+            _data.AddRange(data);
 
-            while (this._data.Count > 4 + 1)
+            while (_data.Count > 4 + 1)
             {
                 //  Extract packet length
-                var packetLength = (this._data[0] << 24 | this._data[1] << 16 | this._data[2] << 8 | this._data[3]);
+                var packetLength = (_data[0] << 24 | _data[1] << 16 | _data[2] << 8 | _data[3]);
 
                 //  Check if complete packet data is available
-                if (this._data.Count < packetLength + 4)
+                if (_data.Count < packetLength + 4)
                 {
                     //  Wait for complete message to arrive first
                     break;
                 }
-                this._data.RemoveRange(0, 4);
+                _data.RemoveRange(0, 4);
 
                 //  Create buffer to hold packet data
                 var packetData = new byte[packetLength];
 
                 //  Cope packet data to array
-                this._data.CopyTo(0, packetData, 0, packetLength);
+                _data.CopyTo(0, packetData, 0, packetLength);
 
                 //  Remove loaded data from _data holder
-                this._data.RemoveRange(0, packetLength);
+                _data.RemoveRange(0, packetLength);
 
                 //  Load SFTP Message and handle it
-                var response = SftpMessage.Load(this.ProtocolVersion, packetData, this.Encoding);
+                var response = SftpMessage.Load(ProtocolVersion, packetData, Encoding);
 
                 try
                 {
                     var versionResponse = response as SftpVersionResponse;
                     if (versionResponse != null)
                     {
-                        this.ProtocolVersion = versionResponse.Version;
-                        this._supportedExtensions = versionResponse.Extentions;
+                        ProtocolVersion = versionResponse.Version;
+                        _supportedExtensions = versionResponse.Extentions;
 
-                        this._sftpVersionConfirmed.Set();
+                        _sftpVersionConfirmed.Set();
                     }
                     else
                     {
-                        this.HandleResponse(response as SftpResponse);
+                        HandleResponse(response as SftpResponse);
                     }
                 }
                 catch (Exception exp)
                 {
-                    this.RaiseError(exp);
+                    RaiseError(exp);
                     break;
                 }
             }
@@ -229,22 +228,22 @@ namespace Renci.SshNet.Sftp
 
             if (disposing)
             {
-                if (this._sftpVersionConfirmed != null)
+                if (_sftpVersionConfirmed != null)
                 {
-                    this._sftpVersionConfirmed.Dispose();
-                    this._sftpVersionConfirmed = null;
+                    _sftpVersionConfirmed.Dispose();
+                    _sftpVersionConfirmed = null;
                 }
             }
         }
 
         private void SendRequest(SftpRequest request)
         {
-            lock (this._requests)
+            lock (_requests)
             {
-                this._requests.Add(request.RequestId, request);
+                _requests.Add(request.RequestId, request);
             }
 
-            this.SendMessage(request);
+            SendMessage(request);
         }
 
         #region SFTP API functions
@@ -263,21 +262,21 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpOpenRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding, flags,
+                var request = new SftpOpenRequest(ProtocolVersion, NextRequestId, path, Encoding, flags,
                     response =>
-                    {
-                        handle = response.Handle;
-                        wait.Set();
-                    },
+                        {
+                            handle = response.Handle;
+                            wait.Set();
+                        },
                     response =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (!nullOnError && exception != null)
@@ -298,16 +297,16 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpCloseRequest(this.ProtocolVersion, this.NextRequestId, handle,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpCloseRequest(ProtocolVersion, NextRequestId, handle,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -331,24 +330,24 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpReadRequest(this.ProtocolVersion, this.NextRequestId, handle, offset, length,
-                    (response) =>
-                    {
-                        data = response.Data;
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        if (response.StatusCode != StatusCodes.Eof)
+                var request = new SftpReadRequest(ProtocolVersion, NextRequestId, handle, offset, length,
+                    response =>
                         {
-                            exception = this.GetSftpException(response);
-                        }
-                        wait.Set();
-                    });
+                            data = response.Data;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            if (response.StatusCode != StatusCodes.Eof)
+                            {
+                                exception = GetSftpException(response);
+                            }
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -371,23 +370,23 @@ namespace Renci.SshNet.Sftp
         {
             SshException exception = null;
 
-            var request = new SftpWriteRequest(this.ProtocolVersion, this.NextRequestId, handle, offset, data,
-                (response) =>
-                {
-                    if (writeCompleted != null)
+            var request = new SftpWriteRequest(ProtocolVersion, NextRequestId, handle, offset, data,
+                response =>
                     {
-                        writeCompleted(response);
-                    }
+                        if (writeCompleted != null)
+                        {
+                            writeCompleted(response);
+                        }
 
-                    exception = this.GetSftpException(response);
-                    if (wait != null)
-                        wait.Set();
-                });
+                        exception = GetSftpException(response);
+                        if (wait != null)
+                            wait.Set();
+                    });
 
-            this.SendRequest(request);
+            SendRequest(request);
 
             if (wait != null)
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
 
             if (exception != null)
             {
@@ -409,21 +408,21 @@ namespace Renci.SshNet.Sftp
             SftpFileAttributes attributes = null;
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpLStatRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        attributes = response.Attributes;
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpLStatRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            attributes = response.Attributes;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -448,21 +447,21 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpFStatRequest(this.ProtocolVersion, this.NextRequestId, handle,
-                    (response) =>
-                    {
-                        attributes = response.Attributes;
-                        wait.Set();
-                    },
+                var request = new SftpFStatRequest(ProtocolVersion, NextRequestId, handle,
+                    response =>
+                        {
+                            attributes = response.Attributes;
+                            wait.Set();
+                        },
                     (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -484,16 +483,16 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpSetStatRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding, attributes,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpSetStatRequest(ProtocolVersion, NextRequestId, path, Encoding, attributes,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -513,16 +512,16 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpFSetStatRequest(this.ProtocolVersion, this.NextRequestId, handle, attributes,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpFSetStatRequest(ProtocolVersion, NextRequestId, handle, attributes,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -545,21 +544,21 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpOpenDirRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        handle = response.Handle;
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpOpenDirRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            handle = response.Handle;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (!nullOnError && exception != null)
@@ -583,24 +582,24 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpReadDirRequest(this.ProtocolVersion, this.NextRequestId, handle,
-                    (response) =>
-                    {
-                        result = response.Files;
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        if (response.StatusCode != StatusCodes.Eof)
+                var request = new SftpReadDirRequest(ProtocolVersion, NextRequestId, handle,
+                    response =>
                         {
-                            exception = this.GetSftpException(response);
-                        }
-                        wait.Set();
-                    });
+                            result = response.Files;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            if (response.StatusCode != StatusCodes.Eof)
+                            {
+                                exception = GetSftpException(response);
+                            }
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -621,16 +620,16 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpRemoveRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpRemoveRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -649,16 +648,16 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpMkDirRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpMkDirRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -677,16 +676,16 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpRmDirRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpRmDirRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -709,21 +708,21 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpRealPathRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        result = response.Files;
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpRealPathRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            result = response.Files;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (!nullOnError && exception != null)
@@ -750,21 +749,21 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpStatRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        attributes = response.Attributes;
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpStatRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            attributes = response.Attributes;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (!nullOnError && exception != null)
@@ -782,25 +781,25 @@ namespace Renci.SshNet.Sftp
         /// <param name="newPath">The new path.</param>
         internal void RequestRename(string oldPath, string newPath)
         {
-            if (this.ProtocolVersion < 2)
+            if (ProtocolVersion < 2)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_RENAME operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_RENAME operation is not supported in {0} version that server operates in.", ProtocolVersion));
             }
 
             SshException exception = null;
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpRenameRequest(this.ProtocolVersion, this.NextRequestId, oldPath, newPath, this.Encoding,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpRenameRequest(ProtocolVersion, NextRequestId, oldPath, newPath, Encoding,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -817,9 +816,9 @@ namespace Renci.SshNet.Sftp
         /// <returns></returns>
         internal KeyValuePair<string, SftpFileAttributes>[] RequestReadLink(string path, bool nullOnError = false)
         {
-            if (this.ProtocolVersion < 3)
+            if (ProtocolVersion < 3)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_READLINK operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_READLINK operation is not supported in {0} version that server operates in.", ProtocolVersion));
             }
 
             SshException exception = null;
@@ -828,22 +827,21 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpReadLinkRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        result = response.Files;
-
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpReadLinkRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            result = response.Files;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (!nullOnError && exception != null)
@@ -861,25 +859,25 @@ namespace Renci.SshNet.Sftp
         /// <param name="targetpath">The targetpath.</param>
         internal void RequestSymLink(string linkpath, string targetpath)
         {
-            if (this.ProtocolVersion < 3)
+            if (ProtocolVersion < 3)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_SYMLINK operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_SYMLINK operation is not supported in {0} version that server operates in.", ProtocolVersion));
             }
 
             SshException exception = null;
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new SftpSymLinkRequest(this.ProtocolVersion, this.NextRequestId, linkpath, targetpath, this.Encoding,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new SftpSymLinkRequest(ProtocolVersion, NextRequestId, linkpath, targetpath, Encoding,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -899,28 +897,28 @@ namespace Renci.SshNet.Sftp
         /// <param name="newPath">The new path.</param>
         internal void RequestPosixRename(string oldPath, string newPath)
         {
-            if (this.ProtocolVersion < 3)
+            if (ProtocolVersion < 3)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", ProtocolVersion));
             }
 
             SshException exception = null;
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new PosixRenameRequest(this.ProtocolVersion, this.NextRequestId, oldPath, newPath, this.Encoding,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new PosixRenameRequest(ProtocolVersion, NextRequestId, oldPath, newPath, Encoding,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                if (!this._supportedExtensions.ContainsKey(request.Name))
+                if (!_supportedExtensions.ContainsKey(request.Name))
                     throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Extension method {0} currently not supported by the server.", request.Name));
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -937,9 +935,9 @@ namespace Renci.SshNet.Sftp
         /// <returns></returns>
         internal SftpFileSytemInformation RequestStatVfs(string path, bool nullOnError = false)
         {
-            if (this.ProtocolVersion < 3)
+            if (ProtocolVersion < 3)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", ProtocolVersion));
             }
 
             SshException exception = null;
@@ -948,25 +946,24 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new StatVfsRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding,
-                    (response) =>
-                    {
-                        information = response.GetReply<StatVfsReplyInfo>().Information;
-
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new StatVfsRequest(ProtocolVersion, NextRequestId, path, Encoding,
+                    response =>
+                        {
+                            information = response.GetReply<StatVfsReplyInfo>().Information;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                if (!this._supportedExtensions.ContainsKey(request.Name))
+                if (!_supportedExtensions.ContainsKey(request.Name))
                     throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Extension method {0} currently not supported by the server.", request.Name));
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (!nullOnError && exception != null)
@@ -986,9 +983,9 @@ namespace Renci.SshNet.Sftp
         /// <exception cref="System.NotSupportedException"></exception>
         internal SftpFileSytemInformation RequestFStatVfs(byte[] handle, bool nullOnError = false)
         {
-            if (this.ProtocolVersion < 3)
+            if (ProtocolVersion < 3)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", ProtocolVersion));
             }
 
             SshException exception = null;
@@ -997,25 +994,24 @@ namespace Renci.SshNet.Sftp
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new FStatVfsRequest(this.ProtocolVersion, this.NextRequestId, handle,
-                    (response) =>
-                    {
-                        information = response.GetReply<StatVfsReplyInfo>().Information;
-
-                        wait.Set();
-                    },
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new FStatVfsRequest(ProtocolVersion, NextRequestId, handle,
+                    response =>
+                        {
+                            information = response.GetReply<StatVfsReplyInfo>().Information;
+                            wait.Set();
+                        },
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                if (!this._supportedExtensions.ContainsKey(request.Name))
+                if (!_supportedExtensions.ContainsKey(request.Name))
                     throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Extension method {0} currently not supported by the server.", request.Name));
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
             
             if (!nullOnError && exception != null)
@@ -1033,28 +1029,28 @@ namespace Renci.SshNet.Sftp
         /// <param name="newPath">The new path.</param>
         internal void HardLink(string oldPath, string newPath)
         {
-            if (this.ProtocolVersion < 3)
+            if (ProtocolVersion < 3)
             {
-                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", this.ProtocolVersion));
+                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "SSH_FXP_EXTENDED operation is not supported in {0} version that server operates in.", ProtocolVersion));
             }
 
             SshException exception = null;
 
             using (var wait = new AutoResetEvent(false))
             {
-                var request = new HardLinkRequest(this.ProtocolVersion, this.NextRequestId, oldPath, newPath,
-                    (response) =>
-                    {
-                        exception = this.GetSftpException(response);
-                        wait.Set();
-                    });
+                var request = new HardLinkRequest(ProtocolVersion, NextRequestId, oldPath, newPath,
+                    response =>
+                        {
+                            exception = GetSftpException(response);
+                            wait.Set();
+                        });
 
-                if (!this._supportedExtensions.ContainsKey(request.Name))
+                if (!_supportedExtensions.ContainsKey(request.Name))
                     throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Extension method {0} currently not supported by the server.", request.Name));
 
-                this.SendRequest(request);
+                SendRequest(request);
 
-                this.WaitOnHandle(wait, this._operationTimeout);
+                WaitOnHandle(wait, OperationTimeout);
             }
 
             if (exception != null)
@@ -1126,25 +1122,22 @@ namespace Renci.SshNet.Sftp
             {
                 return new SftpPermissionDeniedException(response.ErrorMessage);
             }
-            else if (response.StatusCode == StatusCodes.NoSuchFile)
+            if (response.StatusCode == StatusCodes.NoSuchFile)
             {
                 return new SftpPathNotFoundException(response.ErrorMessage);
             }
-            else
-            {
-                return new SshException(response.ErrorMessage);
-            }
+            return new SshException(response.ErrorMessage);
         }
 
         private void HandleResponse(SftpResponse response)
         {
             SftpRequest request;
-            lock (this._requests)
+            lock (_requests)
             {
-                this._requests.TryGetValue(response.ResponseId, out request);
+                _requests.TryGetValue(response.ResponseId, out request);
                 if (request != null)
                 {
-                    this._requests.Remove(response.ResponseId);
+                    _requests.Remove(response.ResponseId);
                 }
             }
 

+ 39 - 39
Renci.SshClient/Renci.SshNet/SubsystemSession.cs

@@ -5,7 +5,7 @@ using System.Threading;
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 
-namespace Renci.SshNet.Sftp
+namespace Renci.SshNet
 {
     /// <summary>
     /// Base class for SSH subsystem implementations
@@ -22,7 +22,7 @@ namespace Renci.SshNet.Sftp
         /// <summary>
         /// Specifies a timeout to wait for operation to complete
         /// </summary>
-        protected TimeSpan _operationTimeout;
+        protected TimeSpan OperationTimeout { get; private set; }
 
         /// <summary>
         /// Occurs when an error occurred.
@@ -67,10 +67,10 @@ namespace Renci.SshNet.Sftp
             if (encoding == null)
                 throw new ArgumentNullException("encoding");
 
-            this._session = session;
-            this._subsystemName = subsystemName;
-            this._operationTimeout = operationTimeout;
-            this.Encoding = encoding;
+            _session = session;
+            _subsystemName = subsystemName;
+            OperationTimeout = operationTimeout;
+            Encoding = encoding;
         }
 
         /// <summary>
@@ -78,15 +78,15 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         public void Connect()
         {
-            this._channel = this._session.CreateChannelSession();
-
-            this._session.ErrorOccured += Session_ErrorOccured;
-            this._session.Disconnected += Session_Disconnected;
-            this._channel.DataReceived += Channel_DataReceived;
-            this._channel.Closed += Channel_Closed;
-            this._channel.Open();
-            this._channel.SendSubsystemRequest(_subsystemName);
-            this.OnChannelOpen();
+            _channel = _session.CreateChannelSession();
+
+            _session.ErrorOccured += Session_ErrorOccured;
+            _session.Disconnected += Session_Disconnected;
+            _channel.DataReceived += Channel_DataReceived;
+            _channel.Closed += Channel_Closed;
+            _channel.Open();
+            _channel.SendSubsystemRequest(_subsystemName);
+            OnChannelOpen();
         }
 
         /// <summary>
@@ -94,8 +94,8 @@ namespace Renci.SshNet.Sftp
         /// </summary>
         public void Disconnect()
         {
-            this._channel.SendEof();
-            this._channel.Close();
+            _channel.SendEof();
+            _channel.Close();
         }
 
         /// <summary>
@@ -104,7 +104,7 @@ namespace Renci.SshNet.Sftp
         /// <param name="data">The data to be sent.</param>
         public void SendData(byte[] data)
         {
-            this._channel.SendData(data);
+            _channel.SendData(data);
         }
 
         /// <summary>
@@ -125,7 +125,7 @@ namespace Renci.SshNet.Sftp
         /// <param name="error">The error.</param>
         protected void RaiseError(Exception error)
         {
-            this._exception = error;
+            _exception = error;
 
             var errorOccuredWaitHandle = _errorOccuredWaitHandle;
             if (errorOccuredWaitHandle != null)
@@ -135,7 +135,7 @@ namespace Renci.SshNet.Sftp
 
         private void Channel_DataReceived(object sender, ChannelDataEventArgs e)
         {
-            this.OnDataReceived(e.DataTypeCode, e.Data);
+            OnDataReceived(e.DataTypeCode, e.Data);
         }
 
         private void Channel_Closed(object sender, ChannelEventArgs e)
@@ -149,15 +149,15 @@ namespace Renci.SshNet.Sftp
         {
             var waitHandles = new[]
                 {
-                    this._errorOccuredWaitHandle,
-                    this._channelClosedWaitHandle,
+                    _errorOccuredWaitHandle,
+                    _channelClosedWaitHandle,
                     waitHandle
                 };
 
             switch (WaitHandle.WaitAny(waitHandles, operationTimeout))
             {
                 case 0:
-                    throw this._exception;
+                    throw _exception;
                 case 1:
                     throw new SshException("Channel was closed.");
                 case WaitHandle.WaitTimeout:
@@ -168,12 +168,12 @@ namespace Renci.SshNet.Sftp
         private void Session_Disconnected(object sender, EventArgs e)
         {
             SignalDisconnected();
-            this.RaiseError(new SshException("Connection was lost"));
+            RaiseError(new SshException("Connection was lost"));
         }
 
         private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
         {
-            this.RaiseError(e.Exception);
+            RaiseError(e.Exception);
         }
 
         private void SignalErrorOccurred(Exception error)
@@ -214,34 +214,34 @@ namespace Renci.SshNet.Sftp
         protected virtual void Dispose(bool disposing)
         {
             // Check to see if Dispose has already been called.
-            if (!this._isDisposed)
+            if (!_isDisposed)
             {
-                if (this._channel != null)
+                if (_channel != null)
                 {
-                    this._channel.DataReceived -= Channel_DataReceived;
-                    this._channel.Closed -= Channel_Closed;
-                    this._channel.Dispose();
-                    this._channel = null;
+                    _channel.DataReceived -= Channel_DataReceived;
+                    _channel.Closed -= Channel_Closed;
+                    _channel.Dispose();
+                    _channel = null;
                 }
 
-                this._session.ErrorOccured -= Session_ErrorOccured;
-                this._session.Disconnected -= Session_Disconnected;
+                _session.ErrorOccured -= Session_ErrorOccured;
+                _session.Disconnected -= Session_Disconnected;
 
                 // If disposing equals true, dispose all managed
                 // and unmanaged resources.
                 if (disposing)
                 {
                     // Dispose managed resources.
-                    if (this._errorOccuredWaitHandle != null)
+                    if (_errorOccuredWaitHandle != null)
                     {
-                        this._errorOccuredWaitHandle.Dispose();
-                        this._errorOccuredWaitHandle = null;
+                        _errorOccuredWaitHandle.Dispose();
+                        _errorOccuredWaitHandle = null;
                     }
 
-                    if (this._channelClosedWaitHandle != null)
+                    if (_channelClosedWaitHandle != null)
                     {
-                        this._channelClosedWaitHandle.Dispose();
-                        this._channelClosedWaitHandle = null;
+                        _channelClosedWaitHandle.Dispose();
+                        _channelClosedWaitHandle = null;
                     }
                 }