public void GetBytes() { var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); var bytes = request.GetBytes(); var expectedBytesLength = 0; expectedBytesLength += 4; // Length expectedBytesLength += 1; // Type expectedBytesLength += 4; // RequestId expectedBytesLength += 4; // OldPath length expectedBytesLength += _oldPathBytes.Length; // OldPath expectedBytesLength += 4; // NewPath length expectedBytesLength += _newPathBytes.Length; // NewPath Assert.AreEqual(expectedBytesLength, bytes.Length); var sshDataStream = new SshDataStream(bytes); Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); Assert.AreEqual((byte) SftpMessageTypes.Rename, sshDataStream.ReadByte()); Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); var actualOldPath = new byte[_oldPathBytes.Length]; sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); var actualNewPath = new byte[_newPathBytes.Length]; sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); Assert.IsTrue(sshDataStream.IsEndOfData); }
public void Constructor() { var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); Assert.AreSame(_encoding, request.Encoding); Assert.AreEqual(_newPath, request.NewPath); Assert.AreEqual(_oldPath, request.OldPath); Assert.AreEqual(_protocolVersion, request.ProtocolVersion); Assert.AreEqual(_requestId, request.RequestId); Assert.AreEqual(SftpMessageTypes.Rename, request.SftpMessageType); }
public void Complete_SftpStatusResponse() { var statusActionInvocations = new List<SftpStatusResponse>(); Action<SftpStatusResponse> statusAction = statusActionInvocations.Add; var statusResponse = new SftpStatusResponse(_protocolVersion); var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); request.Complete(statusResponse); Assert.AreEqual(1, statusActionInvocations.Count); Assert.AreSame(statusResponse, statusActionInvocations[0]); }
/// <summary> /// Performs SSH_FXP_RENAME request. /// </summary> /// <param name="oldPath">The old path.</param> /// <param name="newPath">The new path.</param> internal void RequestRename(string oldPath, string newPath) { if (this.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)); } 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(); }); this.SendRequest(request); this.WaitHandle(wait, this._operationTimeout); } if (exception != null) { throw exception; } }
/// <summary> /// Performs SSH_FXP_RENAME request. /// </summary> /// <param name="oldPath">The old path.</param> /// <param name="newPath">The new path.</param> internal void RequestRename(string oldPath, string newPath) { using (var wait = new AutoResetEvent(false)) { var request = new SftpRenameRequest(this.NextRequestId, oldPath, newPath, (response) => { if (response.StatusCode == StatusCodes.Ok) { wait.Set(); } else { this.ThrowSftpException(response); } }); this.SendRequest(request); this.WaitHandle(wait, this._operationTimeout); } }