예제 #1
0
        private ITFtpCommand ParseInternal(byte[] message)
        {
            TFtpStreamReader reader = new TFtpStreamReader(new MemoryStream(message));

            ushort opcode = reader.ReadUInt16();

            switch (opcode)
            {
            case ReadRequest.OpCode:
                return(ParseReadRequest(reader));

            case WriteRequest.OpCode:
                return(ParseWriteRequest(reader));

            case Data.OpCode:
                return(ParseData(reader));

            case Acknowledgement.OpCode:
                return(ParseAcknowledgement(reader));

            case Error.OpCode:
                return(ParseError(reader));

            case OptionAcknowledgement.OpCode:
                return(ParseOptionAcknowledgement(reader));

            default:
                throw new TFtpParserException("Invalid opcode");
            }
        }
예제 #2
0
        private Data ParseData(TFtpStreamReader reader)
        {
            ushort blockNumber = reader.ReadUInt16();

            byte[] data = reader.ReadBytes(10000);
            return(new Data(blockNumber, data));
        }
예제 #3
0
        private Error ParseError(TFtpStreamReader reader)
        {
            ushort errorCode = reader.ReadUInt16();
            string message   = ParseNullTerminatedString(reader);

            return(new Error(errorCode, message));
        }
예제 #4
0
        private Acknowledgement ParseAcknowledgement(TFtpStreamReader reader)
        {
            ushort blockNumber = reader.ReadUInt16();

            return(new Acknowledgement(blockNumber));
        }