Пример #1
0
        private void serverSocket_OnCommandReceived(ITftpCommand command, EndPoint endpoint)
        {
            //Ignore all other commands
            if (!(command is ReadOrWriteRequest))
            {
                return;
            }

            //Open a connection to the client
            ITransferChannel channel = TransferChannelFactory.CreateConnection(endpoint, new IPEndPoint(localInterface, 0));

            //Create a wrapper for the transfer request
            ReadOrWriteRequest request  = (ReadOrWriteRequest)command;
            ITftpTransfer      transfer = request is ReadRequest ? (ITftpTransfer) new LocalReadTransfer(channel, request.Filename, request.Options) : new LocalWriteTransfer(channel, request.Filename, request.Options);

            if (command is ReadRequest)
            {
                RaiseOnReadRequest(transfer, endpoint);
            }
            else if (command is WriteRequest)
            {
                RaiseOnWriteRequest(transfer, endpoint);
            }
            else
            {
                throw new Exception("Unexpected tftp transfer request: " + command);
            }
        }
Пример #2
0
            private void OnReadOrWriteRequest(ReadOrWriteRequest command)
            {
                writer.WriteBytes(Encoding.ASCII.GetBytes(command.Filename));
                writer.WriteByte(0);
                writer.WriteBytes(Encoding.ASCII.GetBytes(command.Mode.ToString()));
                writer.WriteByte(0);

                if (command.Options != null)
                {
                    foreach (var option in command.Options)
                    {
                        writer.WriteBytes(Encoding.ASCII.GetBytes(option.Name));
                        writer.WriteByte(0);
                        writer.WriteBytes(Encoding.ASCII.GetBytes(option.Value));
                        writer.WriteByte(0);
                    }
                }
            }