示例#1
0
        public override void OnData(Commands.Data command)
        {
            Receiving nextState = new Receiving();

            Context.SetState(nextState);
            nextState.OnCommand(command, Context.GetConnection().RemoteEndpoint);
        }
示例#2
0
        public override void OnCommand(ITFtpCommand command, EndPoint endpoint)
        {
            if (command is Commands.Data || command is OptionAcknowledgement)
            {
                // The server acknowledged our read request.
                // Fix out remote endpoint
                Context.GetConnection().RemoteEndpoint = endpoint;
            }

            switch (command)
            {
            case Commands.Data _:
            {
                if (Context.NegotiatedOptions == null)
                {
                    Context.FinishOptionNegotiation(TransferOptionSet.NewEmptySet());
                }

                // Switch to the receiving state...
                ITransferState nextState = new Receiving();
                Context.SetState(nextState);

                // ...and let it handle the data packet
                nextState.OnCommand(command, endpoint);
                break;
            }

            case OptionAcknowledgement optionAcknowledgement:
                // Check which options were acknowledged
                Context.FinishOptionNegotiation(new TransferOptionSet(optionAcknowledgement.Options));

                // the server acknowledged our options. Confirm the final options
                SendAndRepeat(new Acknowledgement(0));
                break;

            case Error error:
                Context.SetState(new ReceivedError(error));
                break;

            default:
                base.OnCommand(command, endpoint);
                break;
            }
        }