Example #1
0
        public void sendFileEntry(FileStruct file, IOStream ioStream, UInt32 baseflags)
        {
            UInt32 flags = baseflags;
            int    l1 = 0, l2 = 0;

            if (ioStream == null)
            {
                return;
            }
            if (file == null)
            {
                ioStream.writeByte(0);
                lastName = String.Empty;
                return;
            }
            string fileName = file.GetFullName().Replace(":", String.Empty);

            for (l1 = 0;
                 lastName.Length > l1 && (fileName[l1] == lastName[l1]) && (l1 < 255);
                 l1++)
            {
            }
            l2 = fileName.Substring(l1).Length;

            flags |= Options.XMIT_SAME_NAME;

            if (l2 > 255)
            {
                flags |= Options.XMIT_LONG_NAME;
            }
            if (options.protocolVersion >= 28)
            {
                if (flags == 0 && !Util.S_ISDIR(file.mode))
                {
                    flags |= Options.XMIT_TOP_DIR;
                }

                /*if ((flags & 0xFF00) > 0 || flags == 0)
                 * {
                 *  flags |= Options.XMIT_EXTENDED_FLAGS;
                 *  f.writeByte((byte)flags);
                 *  f.writeByte((byte)(flags >> 8));
                 * }
                 * else					*/
                ioStream.writeByte((byte)flags);
            }
            else
            {
                if ((flags & 0xFF) == 0 && !Util.S_ISDIR(file.mode))
                {
                    flags |= Options.XMIT_TOP_DIR;
                }
                if ((flags & 0xFF) == 0)
                {
                    flags |= Options.XMIT_LONG_NAME;
                }
                ioStream.writeByte((byte)flags);
            }
            if ((flags & Options.XMIT_SAME_NAME) != 0)
            {
                ioStream.writeByte((byte)l1);
            }
            if ((flags & Options.XMIT_LONG_NAME) != 0)
            {
                ioStream.writeInt(l2);
            }
            else
            {
                ioStream.writeByte((byte)l2);
            }


            byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(fileName);

            ioStream.Write(b, l1, l2);
            ioStream.WriteLongInt(file.length);


            if ((flags & Options.XMIT_SAME_TIME) == 0)
            {
                ioStream.writeInt(file.modTime.Second);
            }
            if ((flags & Options.XMIT_SAME_MODE) == 0)
            {
                ioStream.writeInt((int)file.mode);
            }
            if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0)
            {
                ioStream.writeInt(file.uid);
            }
            if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 0)
            {
                ioStream.writeInt(file.gid);
            }
            if (options.alwaysChecksum)
            {
                byte[] sum;
                if (!Util.S_ISDIR(file.mode))
                {
                    sum = file.sum;
                }
                else if (options.protocolVersion < 28)
                {
                    sum = new byte[16];
                }
                else
                {
                    sum = null;
                }

                if (sum != null)
                {
                    ioStream.Write(sum, 0, options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH);
                }
            }

            lastName = fileName;
        }
Example #2
0
		public void sendFileEntry(FileStruct file, IOStream f, UInt32 baseflags)
		{
			UInt32 flags = baseflags;
			int l1 = 0,l2 = 0;

			if(f == null)
				return;
			if(file == null)
			{
				f.writeByte(0);
				lastName = "";
				return;
			}
			string fileName = file.FNameTo().Replace(":","");
			for (l1 = 0;
				lastName.Length >l1 && (fileName[l1] == lastName[l1]) && (l1 < 255);
				l1++) {}
			l2 = fileName.Substring(l1).Length;

			flags |= Options.XMIT_SAME_NAME;			

			if (l2 > 255)
				flags |= Options.XMIT_LONG_NAME; 
			if(options.protocolVersion >= 28)
			{
				if(flags == 0 && !Util.S_ISDIR(file.mode))
					flags |= Options.XMIT_TOP_DIR; 
				/*if ((flags & 0xFF00) > 0 || flags == 0) 
				{
					flags |= Options.XMIT_EXTENDED_FLAGS;
					f.writeByte((byte)flags);
					f.writeByte((byte)(flags >> 8));
				} 
				else					*/
					f.writeByte((byte)flags); 
			} else 
			{
				if ((flags & 0xFF) == 0 && !Util.S_ISDIR(file.mode))
					flags |= Options.XMIT_TOP_DIR;
				if ((flags & 0xFF) == 0)
					flags |= Options.XMIT_LONG_NAME;
				f.writeByte((byte)flags);
			}
			if ((flags & Options.XMIT_SAME_NAME) != 0)
				f.writeByte((byte)l1);
			if ((flags & Options.XMIT_LONG_NAME) != 0)
				f.writeInt(l2);
			else
				f.writeByte((byte)l2); 	
			
			
			byte[] b =System.Text.ASCIIEncoding.ASCII.GetBytes(fileName);

			f.Write(b, l1, l2);
			f.WriteLongInt(file.length); 

			
			if ((flags & Options.XMIT_SAME_TIME) == 0)
				f.writeInt(file.modTime.Second);
			if ((flags & Options.XMIT_SAME_MODE) == 0)
				f.writeInt((int)file.mode);
			if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0) 
			{				
				f.writeInt(file.uid);
			}
			if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 0) 
			{				
				f.writeInt(file.gid);
			}
			if (options.alwaysChecksum ) 
			{
				byte[] sum;	
				if(!Util.S_ISDIR(file.mode))
					sum = file.sum;				
				else if(options.protocolVersion < 28)
					sum = new byte[16];
				else 
					sum = null;

				if (sum != null ) 
				{										
					f.Write(sum, 0, options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH);
				}

			}

			lastName = fileName;
		}