Exemple #1
0
        /// <summary>
        /// Performs SSH_FXP_SYMLINK request.
        /// </summary>
        /// <param name="linkpath">The linkpath.</param>
        /// <param name="targetpath">The targetpath.</param>
        internal void RequestSymLink(string linkpath, string targetpath)
        {
            if (this.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));
            }

            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();
                });

                this.SendRequest(request);

                this.WaitOnHandle(wait, this._operationTimeout);
            }

            if (exception != null)
            {
                throw exception;
            }
        }
        public void GetBytes()
        {
            var request = new SftpSymLinkRequest(
                _protocolVersion,
                _requestId,
                _newLinkPath,
                _existingPath,
                _encoding,
                null);

            var bytes = request.GetBytes();

            var expectedBytesLength = 0;

#if TUNING
            expectedBytesLength += 4;                         // Length
#endif
            expectedBytesLength += 1;                         // Type
            expectedBytesLength += 4;                         // RequestId
            expectedBytesLength += 4;                         // NewLinkPath length
            expectedBytesLength += _newLinkPathBytes.Length;  // NewLinkPath
            expectedBytesLength += 4;                         // ExistingPath length
            expectedBytesLength += _existingPathBytes.Length; // ExistingPath

            Assert.AreEqual(expectedBytesLength, bytes.Length);

            var sshDataStream = new SshDataStream(bytes);

#if TUNING
            Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32());
#endif
            Assert.AreEqual((byte)SftpMessageTypes.SymLink, sshDataStream.ReadByte());
            Assert.AreEqual(_requestId, sshDataStream.ReadUInt32());

            Assert.AreEqual((uint)_newLinkPathBytes.Length, sshDataStream.ReadUInt32());
            var actualNewLinkPath = new byte[_newLinkPathBytes.Length];
            sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length);
            Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath));

            Assert.AreEqual((uint)_existingPathBytes.Length, sshDataStream.ReadUInt32());
            var actualExistingPath = new byte[_existingPathBytes.Length];
            sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length);
            Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath));

            Assert.IsTrue(sshDataStream.IsEndOfData);
        }
        public void Constructor()
        {
            var request = new SftpSymLinkRequest(
                _protocolVersion,
                _requestId,
                _newLinkPath,
                _existingPath,
                _encoding,
                null);

            Assert.AreSame(_encoding, request.Encoding);
            Assert.AreEqual(_existingPath, request.ExistingPath);
            Assert.AreEqual(_newLinkPath, request.NewLinkPath);
            Assert.AreEqual(_protocolVersion, request.ProtocolVersion);
            Assert.AreEqual(_requestId, request.RequestId);
            Assert.AreEqual(SftpMessageTypes.SymLink, request.SftpMessageType);
        }
        public void Complete_SftpStatusResponse()
        {
            var statusActionInvocations = new List <SftpStatusResponse>();

            Action <SftpStatusResponse> statusAction = statusActionInvocations.Add;
            var statusResponse = new SftpStatusResponse(_protocolVersion);

            var request = new SftpSymLinkRequest(
                _protocolVersion,
                _requestId,
                _newLinkPath,
                _existingPath,
                _encoding,
                statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
        }
Exemple #5
0
        /// <summary>
        /// Performs SSH_FXP_SYMLINK request.
        /// </summary>
        /// <param name="linkpath">The linkpath.</param>
        /// <param name="targetpath">The targetpath.</param>
        internal void RequestSymLink(string linkpath, string targetpath)
        {
            using (var wait = new AutoResetEvent(false))
            {
                var request = new SftpSymLinkRequest(this.NextRequestId, linkpath, targetpath,
                                                     (response) =>
                {
                    if (response.StatusCode == StatusCodes.Ok)
                    {
                        wait.Set();
                    }
                    else
                    {
                        this.ThrowSftpException(response);
                    }
                });

                this.SendRequest(request);

                this.WaitHandle(wait, this._operationTimeout);
            }
        }