/// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbCreateTemporaryRequestPacket(SmbCreateTemporaryRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.FileAttributes = packet.SmbParameters.FileAttributes;
            this.smbParameters.CreationTime = new UTime();
            this.smbParameters.CreationTime.Time = packet.SmbParameters.CreationTime.Time;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            this.smbData.BufferFormat = packet.SmbData.BufferFormat;

            if (packet.smbData.DirectoryName != null)
            {
                this.smbData.DirectoryName = new byte[packet.smbData.DirectoryName.Length];
                Array.Copy(packet.smbData.DirectoryName,
                    this.smbData.DirectoryName, packet.smbData.DirectoryName.Length);
            }
            else
            {
                this.smbData.DirectoryName = new byte[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbCreateTemporaryRequestPacket(SmbCreateTemporaryRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount         = packet.SmbParameters.WordCount;
            this.smbParameters.FileAttributes    = packet.SmbParameters.FileAttributes;
            this.smbParameters.CreationTime      = new UTime();
            this.smbParameters.CreationTime.Time = packet.SmbParameters.CreationTime.Time;

            this.smbData.ByteCount    = packet.SmbData.ByteCount;
            this.smbData.BufferFormat = packet.SmbData.BufferFormat;

            if (packet.smbData.DirectoryName != null)
            {
                this.smbData.DirectoryName = new byte[packet.smbData.DirectoryName.Length];
                Array.Copy(packet.smbData.DirectoryName,
                           this.smbData.DirectoryName, packet.smbData.DirectoryName.Length);
            }
            else
            {
                this.smbData.DirectoryName = new byte[0];
            }
        }
        /// <summary>
        /// to create a CreateTemporary request packet.
        /// </summary>
        /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a
        /// request.</param>
        /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param>
        /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is
        /// accessing.</param>
        /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the
        /// message</param>
        /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the
        /// message. Unspecified bits are reserved and MUST be zero.</param>
        /// <param name="creationTime">The time the file was created on the client represented as the number of seconds
        /// since Jan 1, 1970, 00:00:00.0. Server support of this field is OPTIONAL</param>
        /// <param name="directoryName">A null-terminated string that represents the fully qualified name of the
        /// directory relative to the supplied TID in which to create the temporary file.</param>
        /// <returns>a CreateTemporary request packet</returns>
        public SmbCreateTemporaryRequestPacket CreateCreateTemporaryRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            UTime creationTime,
            string directoryName)
        {
            if (directoryName == null)
            {
                directoryName = string.Empty;
            }

            SmbCreateTemporaryRequestPacket packet = new SmbCreateTemporaryRequestPacket();

            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_CREATE_TEMPORARY,
                messageId, uid, treeId, flags, flags2);

            SMB_COM_CREATE_TEMPORARY_Request_SMB_Parameters smbParameters =
                new SMB_COM_CREATE_TEMPORARY_Request_SMB_Parameters();
            smbParameters.FileAttributes = SmbFileAttributes.SMB_FILE_ATTRIBUTE_NORMAL;
            smbParameters.CreationTime = creationTime;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_CREATE_TEMPORARY_Request_SMB_Data smbData = new SMB_COM_CREATE_TEMPORARY_Request_SMB_Data();
            smbData.BufferFormat = (byte)DataBufferFormat.SmbString;
            smbData.DirectoryName = CifsMessageUtils.ToSmbStringBytes(directoryName,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat) + smbData.DirectoryName.Length);

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return packet;
        }
        public SmbCreateTemporaryResponsePacket CreateCreateTemporaryResponse(
            CifsServerPerConnection connection,
            SmbCreateTemporaryRequestPacket request,
            string temporaryFileName)
        {
            SmbCreateTemporaryResponsePacket response = new SmbCreateTemporaryResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_CREATE_TEMPORARY_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.WordCount = 0x01; // should be 0x1; But it reads 0x02 in TD.
            smbParameters.FID = (ushort)connection.GenerateFID();
            response.SmbParameters = smbParameters;

            SMB_COM_CREATE_TEMPORARY_Response_SMB_Data smbData = response.SmbData;
            smbData.BufferFormat = 0x04;
            smbData.TemporaryFileName = CifsMessageUtils.ToSmbStringBytes(temporaryFileName,
                    (response.SmbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.ByteCount = (ushort)(smbData.TemporaryFileName.Length + Marshal.SizeOf(smbData.BufferFormat));
            response.SmbData = smbData;

            return response;
        }