public void Complete_SftpStatusResponse()
        {
            var statusActionInvocations = new List <SftpStatusResponse>();
            Action <SftpStatusResponse> statusAction = statusActionInvocations.Add;
            var statusResponse = new SftpStatusResponse(_protocolVersion);

            var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
        }
        public void Complete_SftpStatusResponse()
        {
            var statusActionInvocations = new List <SftpStatusResponse>();
            Action <SftpStatusResponse> statusAction = statusActionInvocations.Add;
            var statusResponse = new SftpStatusResponse(_protocolVersion);

            var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
        }
        public void Complete_SftpStatusResponse()
        {
            IList <SftpStatusResponse> statusActionInvocations = new List <SftpStatusResponse>();

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

            var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
        }
        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]);
        }
Esempio n. 5
0
        private static SftpMessage Load(uint protocolVersion, byte[] data, SftpMessageTypes messageType, Encoding encoding)
        {
            SftpMessage message;

            switch (messageType)
            {
            case SftpMessageTypes.Version:
                message = new SftpVersionResponse();
                break;

            case SftpMessageTypes.Status:
                message = new SftpStatusResponse(protocolVersion);
                break;

            case SftpMessageTypes.Data:
                message = new SftpDataResponse(protocolVersion);
                break;

            case SftpMessageTypes.Handle:
                message = new SftpHandleResponse(protocolVersion);
                break;

            case SftpMessageTypes.Name:
                message = new SftpNameResponse(protocolVersion, encoding);
                break;

            case SftpMessageTypes.Attrs:
                message = new SftpAttrsResponse(protocolVersion);
                break;

            case SftpMessageTypes.ExtendedReply:
                message = new SftpExtendedReplyResponse(protocolVersion);
                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Message type '{0}' is not supported.", messageType));
            }

#if TUNING
            message.Load(data);
#else
            message.LoadBytes(data);

            message.ResetReader();

            message.LoadData();
#endif

            return(message);
        }
Esempio n. 6
0
 private void ThrowSftpException(SftpStatusResponse response)
 {
     if (response.StatusCode == StatusCodes.PermissionDenied)
     {
         throw new SftpPermissionDeniedException(response.ErrorMessage);
     }
     else if (response.StatusCode == StatusCodes.NoSuchFile)
     {
         throw new SftpPathNotFoundException(response.ErrorMessage);
     }
     else
     {
         throw new SshException(response.ErrorMessage);
     }
 }
Esempio n. 7
0
 private SshException GetSftpException(SftpStatusResponse response)
 {
     if (response.StatusCode == StatusCodes.Ok)
     {
         return(null);
     }
     if (response.StatusCode == StatusCodes.PermissionDenied)
     {
         return(new SftpPermissionDeniedException(response.ErrorMessage));
     }
     if (response.StatusCode == StatusCodes.NoSuchFile)
     {
         return(new SftpPathNotFoundException(response.ErrorMessage));
     }
     return(new SshException(response.ErrorMessage));
 }
Esempio n. 8
0
        public void Complete_SftpStatusResponse()
        {
            var statusActionInvocations = new List <SftpStatusResponse>();
            var nameActionInvocations   = new List <SftpNameResponse>();

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

            var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
            Assert.AreEqual(0, nameActionInvocations.Count);
        }
Esempio n. 9
0
        public void Complete_SftpStatusResponse()
        {
            IList <SftpStatusResponse>        statusActionInvocations        = new List <SftpStatusResponse>();
            IList <SftpExtendedReplyResponse> extendedReplyActionInvocations = new List <SftpExtendedReplyResponse>();

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

            var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
            Assert.AreEqual(0, extendedReplyActionInvocations.Count);
        }
Esempio n. 10
0
        private static SshException GetSftpException(SftpStatusResponse response)
        {
            switch (response.StatusCode)
            {
            case StatusCodes.Ok:
                return(null);

            case StatusCodes.PermissionDenied:
                return(new SftpPermissionDeniedException(response.ErrorMessage));

            case StatusCodes.NoSuchFile:
                return(new SftpPathNotFoundException(response.ErrorMessage));

            default:
                return(new SshException(response.ErrorMessage));
            }
        }
Esempio n. 11
0
        public SftpMessage Create(uint protocolVersion, byte messageType, Encoding encoding)
        {
            var sftpMessageType = (SftpMessageTypes)messageType;

            SftpMessage message;

            switch (sftpMessageType)
            {
            case SftpMessageTypes.Version:
                message = new SftpVersionResponse();
                break;

            case SftpMessageTypes.Status:
                message = new SftpStatusResponse(protocolVersion);
                break;

            case SftpMessageTypes.Data:
                message = new SftpDataResponse(protocolVersion);
                break;

            case SftpMessageTypes.Handle:
                message = new SftpHandleResponse(protocolVersion);
                break;

            case SftpMessageTypes.Name:
                message = new SftpNameResponse(protocolVersion, encoding);
                break;

            case SftpMessageTypes.Attrs:
                message = new SftpAttrsResponse(protocolVersion);
                break;

            case SftpMessageTypes.ExtendedReply:
                message = new SftpExtendedReplyResponse(protocolVersion);
                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Message type '{0}' is not supported.", sftpMessageType));
            }

            return(message);
        }
Esempio n. 12
0
        public void Complete_SftpStatusResponse()
        {
            var statusActionInvocations = new List <SftpStatusResponse>();
            var handleActionInvocations = new List <SftpHandleResponse>();

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

            var request = new SftpOpenRequest(
                _protocolVersion,
                _requestId,
                _filename,
                _encoding,
                _flags,
                handleAction,
                statusAction);

            request.Complete(statusResponse);

            Assert.AreEqual(1, statusActionInvocations.Count);
            Assert.AreSame(statusResponse, statusActionInvocations[0]);
            Assert.AreEqual(0, handleActionInvocations.Count);
        }