Exemplo n.º 1
0
        public static DateTime StringToFtpDate(String value)
        {
            //String[] lParts = Regex.Split(value, @"\w+");
            String[] lParts = ParseLine(value, 3);

            return(FtpListingItem.StringToFtpDate(lParts[0], lParts[1], lParts[2]));
        }
Exemplo n.º 2
0
        public void Parse(String list, Boolean includeUpDir)
        {
            this.Clear();

            Boolean lFoundUpDir = false;

            //String[] lItems = Regex.Split(list, @"(?:\r\n|\r|\n)");
            String[] lItems = SplitLines(list);

            for (Int32 i = 0; i < lItems.Length; i++)
            {
                String lItem = lItems[i].Trim();

                if (String.IsNullOrEmpty(lItem))
                {
                    continue;
                }

                if (lItem.ToLower().StartsWith("total"))
                {
                    continue;
                }

                try
                {
                    FtpListingItem lNewItem = new FtpListingItem();
                    lNewItem.Parse(lItem);

                    this.Add(lNewItem);

                    if (lNewItem.Directory && lNewItem.FileName == "..")
                    {
                        lFoundUpDir = true;
                    }
                }
                catch (Exception ex)
                {
                    if (!(ex is FormatException))
                    {
                        if (defined("ECHOES") && (!(ex is IndexOutOfRangeException)))
                        {
                            throw ex;
                        }
                        else if (!defined("ECHOES") && (!(ex is RTLException)))
                        {
                            throw ex;
                        }
                    }
                }
            }

            if (includeUpDir && !lFoundUpDir)
            {
                FtpListingItem lUpItem = new FtpListingItem();
                lUpItem.Directory = true;
                lUpItem.FileName  = "..";
                this.Insert(0, lUpItem);
            }
        }
Exemplo n.º 3
0
        public FtpListingItem Add()
        {
            FtpListingItem lResult = new FtpListingItem();

            this.Add(lResult);

            return(lResult);
        }
Exemplo n.º 4
0
        public override String ToString()
        {
            Char[] lRights = new Char[] { 'd', 'r', 'w', 'x', 'r', 'w', 'x', 'r', 'w', 'x' };

            if (!this.Directory)
            {
                lRights[0] = '-';
            }

            if (!this.UserRead)
            {
                lRights[1] = '-';
            }

            if (!this.UserWrite)
            {
                lRights[2] = '-';
            }

            if (!this.UserExec)
            {
                lRights[3] = '-';
            }

            if (!this.GroupRead)
            {
                lRights[4] = '-';
            }

            if (!this.GroupWrite)
            {
                lRights[5] = '-';
            }

            if (!this.GroupExec)
            {
                lRights[6] = '-';
            }

            if (!this.OtherRead)
            {
                lRights[7] = '-';
            }

            if (!this.OtherWrite)
            {
                lRights[8] = '-';
            }

            if (!this.OtherExec)
            {
                lRights[9] = '-';
            }

            return(String.Format("{0} {1,3} {2,8} {3,8} {4,7} {5} {6}", new String(lRights), this.SubItemCount, this.User,
                                 this.Group, this.Size, FtpListingItem.FtpDateToString(this.FileDate), this.FileName));
        }
Exemplo n.º 5
0
        public void Parse(String list, Boolean includeUpDir)
        {
            this.Clear();

            Boolean lFoundUpDir = false;

            String[] lItems = Regex.Split(list, @"(?:\r\n|\r|\n)");

            for (Int32 i = 0; i < lItems.Length; i++)
            {
                String lItem = lItems[i].Trim();

                if (String.IsNullOrEmpty(lItem))
                {
                    continue;
                }

                if (lItem.StartsWith("total", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                try
                {
                    FtpListingItem lNewItem = new FtpListingItem();
                    lNewItem.Parse(lItem);

                    this.Add(lNewItem);

                    if (lNewItem.Directory && lNewItem.FileName == "..")
                    {
                        lFoundUpDir = true;
                    }
                }
                catch (IndexOutOfRangeException)
                {
                }
                catch (FormatException)
                {
                }
            }

            if (includeUpDir && !lFoundUpDir)
            {
                FtpListingItem lUpItem = new FtpListingItem();
                lUpItem.Directory = true;
                lUpItem.FileName  = "..";
                this.Insert(0, lUpItem);
            }
        }
Exemplo n.º 6
0
		public void Parse(String list, Boolean includeUpDir)
		{
			this.Clear();

			Boolean lFoundUpDir = false;

			String[] lItems = Regex.Split(list, @"(?:\r\n|\r|\n)");

			for (Int32 i = 0; i < lItems.Length; i++)
			{
				String lItem = lItems[i].Trim();

				if (String.IsNullOrEmpty(lItem))
					continue;

				if (lItem.StartsWith("total", StringComparison.OrdinalIgnoreCase))
					continue;

				try
				{
					FtpListingItem lNewItem = new FtpListingItem();
					lNewItem.Parse(lItem);

					this.Add(lNewItem);

					if (lNewItem.Directory && lNewItem.FileName == "..")
						lFoundUpDir = true;
				}
				catch (IndexOutOfRangeException)
				{
				}
				catch (FormatException)
				{
				}
			}

			if (includeUpDir && !lFoundUpDir)
			{
				FtpListingItem lUpItem = new FtpListingItem();
				lUpItem.Directory = true;
				lUpItem.FileName = "..";
				this.Insert(0, lUpItem);
			}
		}
Exemplo n.º 7
0
		public FtpListingItem Add()
		{
			FtpListingItem lResult = new FtpListingItem();
			this.Add(lResult);

			return lResult;
		}
Exemplo n.º 8
0
 public void Retrieve(FtpListingItem item, Stream stream)
 {
     this.Retrieve(item.FileName, item.Size, stream);
 }
Exemplo n.º 9
0
 public void Retrieve(FtpListingItem item, Stream stream)
 {
     this.Retrieve(item.FileName, item.Size, stream);
 }
Exemplo n.º 10
0
        public void Parse(String item)
        {
            Regex lRegEx = new Regex(@"\s+");

            // there is two modes possible Unix mode or MS-DOS mode
            if (item.StartsWith("d") || item.StartsWith("-"))
            {
                /*
                 * Unix Mode
                 * ======================================================================
                 * drwxr-xr-x    3 65025    100          4096 Dec 10 12:13 1 1
                 * drwxr-xr-x    2 65025    100          4096 Dec 10 12:13 2
                 * -rw-r--r--    1 65025    100            35 Dec 10 12:33 root.txt
                 * -rw-r--r--    1 65025    100            43 Dec 10 12:33 root2.txt
                 *
                 *
                 * where
                 * 0 - access
                 * 1 - sub item count
                 * 2 - owner
                 * 3 - group
                 * 4 - size
                 * 5 - Month
                 * 6 - day
                 * 7 - Time or Year
                 * 8 - Filename
                 */
                String[] lSplittedData = lRegEx.Split(item, 9);

                // Copy splitted data to result
                // Problem is that at least one FTP server doesn;t return Group segment
                // So we have to compensate this
                String[] lSegments = new String[9];
                for (Int32 i = 0; i < 3; i++)
                {
                    lSegments[i] = lSplittedData[i];
                }
                for (Int32 i = 1; i <= 6; i++)
                {
                    lSegments[9 - i] = lSplittedData[lSplittedData.Length - i];
                }

                this.Directory  = lSegments[0][0] != '-';
                this.UserRead   = lSegments[0][1] != '-';
                this.UserWrite  = lSegments[0][2] != '-';
                this.UserExec   = lSegments[0][3] != '-';
                this.GroupRead  = lSegments[0][4] != '-';
                this.GroupWrite = lSegments[0][5] != '-';
                this.GroupExec  = lSegments[0][6] != '-';
                this.OtherRead  = lSegments[0][7] != '-';
                this.OtherWrite = lSegments[0][8] != '-';
                this.OtherExec  = lSegments[0][9] != '-';

                this.SubItemCount = Int32.Parse(lSegments[1]);
                this.User         = lSegments[2];
                this.Group        = lSegments[3];
                this.Size         = Int64.Parse(lSegments[4]);

                String lMonthShortName = lSegments[5];
                String lDay            = lSegments[6];
                String lTimeOrYear     = lSegments[7];

                this.FileDate = FtpListingItem.StringToFtpDate(lMonthShortName, lDay, lTimeOrYear);

                this.FileName = lSegments[8];
            }
            else
            {
                /*
                 * MS-DOS Mode
                 * ======================================================================
                 * 01-14-08  01:35PM       <DIR>          1 1
                 * 01-14-08  01:35PM       <DIR>          2
                 * 01-14-08  01:36PM                   35 root.txt
                 * 01-14-08  01:36PM                   43 root2.txt
                 *
                 * where
                 *
                 * 0 - date
                 * 1 - time
                 * 2 - Size or IsDir
                 * 3 - Filename
                 */
                String[] lSegments = lRegEx.Split(item, 4);
                this.Directory = (lSegments[2] == "<DIR>");

                this.Size = this.Directory ? 0 : Int64.Parse(lSegments[2]);

                String lDateStr = lSegments[0];
                String lTimeStr = lSegments[1];
                this.FileDate = FtpListingItem.StringToFtpDate(lDateStr, lTimeStr);

                this.FileName = lSegments[3];
            }
        }