public void GetBytes() { var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); var bytes = request.GetBytes(); var expectedBytesLength = 0; expectedBytesLength += 4; // Length expectedBytesLength += 1; // Type expectedBytesLength += 4; // RequestId expectedBytesLength += 4; // Filename length expectedBytesLength += _filenameBytes.Length; // Filename Assert.AreEqual(expectedBytesLength, bytes.Length); var sshDataStream = new SshDataStream(bytes); Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); Assert.AreEqual((byte)SftpMessageTypes.Remove, sshDataStream.ReadByte()); Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); Assert.AreEqual((uint)_filenameBytes.Length, sshDataStream.ReadUInt32()); var actualFilename = new byte[_filenameBytes.Length]; sshDataStream.Read(actualFilename, 0, actualFilename.Length); Assert.IsTrue(_filenameBytes.SequenceEqual(actualFilename)); Assert.IsTrue(sshDataStream.IsEndOfData); }
public void Constructor() { var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); Assert.AreSame(_encoding, request.Encoding); Assert.AreEqual(_filename, request.Filename); Assert.AreEqual(_protocolVersion, request.ProtocolVersion); Assert.AreEqual(_requestId, request.RequestId); Assert.AreEqual(SftpMessageTypes.Remove, request.SftpMessageType); }
public void Complete_SftpStatusResponse() { var statusActionInvocations = new List <SftpStatusResponse>(); Action <SftpStatusResponse> statusAction = statusActionInvocations.Add; var statusResponse = new SftpStatusResponse(_protocolVersion); var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, statusAction); request.Complete(statusResponse); Assert.AreEqual(1, statusActionInvocations.Count); Assert.AreSame(statusResponse, statusActionInvocations[0]); }
/// <summary> /// Performs SSH_FXP_REMOVE request. /// </summary> /// <param name="path">The path.</param> internal void RequestRemove(string path) { using (var wait = new AutoResetEvent(false)) { var request = new SftpRemoveRequest(this.NextRequestId, path, (response) => { if (response.StatusCode == StatusCodes.Ok) { wait.Set(); } else { this.ThrowSftpException(response); } }); this.SendRequest(request); this.WaitHandle(wait, this._operationTimeout); } }
/// <summary> /// Performs SSH_FXP_REMOVE request. /// </summary> /// <param name="path">The path.</param> internal void RequestRemove(string path) { SshException exception = null; using (var wait = new AutoResetEvent(false)) { var request = new SftpRemoveRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding, (response) => { exception = this.GetSftpException(response); wait.Set(); }); this.SendRequest(request); this.WaitOnHandle(wait, this._operationTimeout); } if (exception != null) { throw exception; } }
/// <summary> /// Performs SSH_FXP_REMOVE request. /// </summary> /// <param name="path">The path.</param> public void RequestRemove(string path) { SshException exception = null; using (var wait = new AutoResetEvent(false)) { var request = new SftpRemoveRequest(ProtocolVersion, NextRequestId, path, Encoding, response => { exception = GetSftpException(response); wait.Set(); }); SendRequest(request); WaitOnHandle(wait, OperationTimeout); } if (exception != null) { throw exception; } }