StringToFtpDate() public static method

public static StringToFtpDate ( String value ) : System.DateTime
value String
return System.DateTime
Beispiel #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]));
        }
Beispiel #2
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];
            }
        }