public override void OnData(Data command)
        {
            var nextState = new Receiving();

            Context.SetState(nextState);
            nextState.OnCommand(command, Context.GetConnection().RemoteEndpoint);
        }
Example #2
0
 public override void OnData(Data command)
 {
     if (command.BlockNumber == 1)
     {
         //The client confirmed the options, so let's start receiving
         ITransferState nextState = new Receiving();
         Context.SetState(nextState);
         nextState.OnCommand(command, Context.GetConnection().RemoteEndpoint);
     }
 }
Example #3
0
        public override void OnCommand(ITftpCommand command, EndPoint endpoint)
        {
            if (command is Data || command is OptionAcknowledgement)
            {
                //The server acknowledged our read request.
                //Fix out remote endpoint
                Context.GetConnection().RemoteEndpoint = endpoint;
            }

            if (command is 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);
            }
            else if (command is OptionAcknowledgement)
            {
                //Check which options were acknowledged
                Context.FinishOptionNegotiation(new TransferOptionSet((command as OptionAcknowledgement).Options));

                //the server acknowledged our options. Confirm the final options
                SendAndRepeat(new Acknowledgement(0));
            }
            else if (command is Error)
            {
                Context.SetState(new ReceivedError((Error)command));
            }
            else
            {
                base.OnCommand(command, endpoint);
            }
        }