public void Constructor() { var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); Assert.AreEqual(_name, request.Name); Assert.AreEqual(_newPath, request.NewPath); Assert.AreEqual(_oldPath, request.OldPath); Assert.AreEqual(_protocolVersion, request.ProtocolVersion); Assert.AreEqual(_requestId, request.RequestId); Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); }
public void Complete_SftpStatusResponse() { IList<SftpStatusResponse> statusActionInvocations = new List<SftpStatusResponse>(); Action<SftpStatusResponse> statusAction = statusActionInvocations.Add; var statusResponse = new SftpStatusResponse(_protocolVersion); var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, statusAction); request.Complete(statusResponse); Assert.AreEqual(1, statusActionInvocations.Count); Assert.AreSame(statusResponse, statusActionInvocations[0]); }
public void GetBytes() { var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); var bytes = request.GetBytes(); var expectedBytesLength = 0; expectedBytesLength += 4; // Length expectedBytesLength += 1; // Type expectedBytesLength += 4; // RequestId expectedBytesLength += 4; // Name length expectedBytesLength += _nameBytes.Length; // Name 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.Extended, sshDataStream.ReadByte()); Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); var actualNameBytes = new byte[_nameBytes.Length]; sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); 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); }
/// <summary> /// Performs [email protected] extended request. /// </summary> /// <param name="oldPath">The old path.</param> /// <param name="newPath">The new path.</param> internal void HardLink(string oldPath, string newPath) { if (this.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)); } 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(); }); if (!this._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); this.WaitHandle(wait, this._operationTimeout); } if (exception != null) { throw exception; } }