Exemple #1
0
        /// <summary>
        /// Validate if the current parser is correct
        /// </summary>
        private bool IsParserValid(FtpParser p, string[] files)
        {
            switch (p)
            {
            case FtpParser.Windows:
                return(FtpWindowsParser.IsValid(client, files));

            case FtpParser.Unix:
                return(FtpUnixParser.IsValid(client, files));

            case FtpParser.VMS:
                return(FtpVMSParser.IsValid(client, files));

            case FtpParser.IBMzOS:
                return(FtpIBMzOSParser.IsValid(client, files));

            case FtpParser.IBMOS400:
                return(FtpIBMOS400Parser.IsValid(client, files));

            case FtpParser.NonStop:
                return(FtpNonStopParser.IsValid(client, files));
            }

            return(false);
        }
        /// <summary>
        /// Parse raw file from server into a file object, using the currently active parser.
        /// </summary>
        public FtpListItem ParseSingleLine(string path, string file, List <FtpCapability> caps, bool isMachineList)
        {
            FtpListItem result = null;

            // force machine listing if it is
            if (isMachineList)
            {
                result = FtpMachineListParser.Parse(file, caps, client);
            }
            else
            {
                // use custom parser if given
                if (m_customParser != null)
                {
                    result = m_customParser(file, caps, client);
                }
                else
                {
                    if (IsWrongParser())
                    {
                        ValidateParser(new[] { file });
                    }

                    // use one of the in-built parsers
                    switch (CurrentParser)
                    {
                    case FtpParser.Legacy:
                        result = ParseLegacy(path, file, caps, client);
                        break;

                    case FtpParser.Machine:
                        result = FtpMachineListParser.Parse(file, caps, client);
                        break;

                    case FtpParser.Windows:
                        result = FtpWindowsParser.Parse(client, file);
                        break;

                    case FtpParser.Unix:
                        result = FtpUnixParser.Parse(client, file);
                        break;

                    case FtpParser.UnixAlt:
                        result = FtpUnixParser.ParseUnixAlt(client, file);
                        break;

                    case FtpParser.VMS:
                        result = FtpVMSParser.Parse(client, file);
                        break;

                    case FtpParser.IBM:
                        result = FtpIBMParser.Parse(client, file);
                        break;

                    case FtpParser.NonStop:
                        result = FtpNonStopParser.Parse(client, file);
                        break;
                    }
                }
            }

            // if parsed file successfully
            if (result != null)
            {
                // apply time difference between server/client
                if (HasTimeOffset)
                {
                    result.Modified = result.Modified - TimeOffset;
                }

                // calc absolute file paths
                result.CalculateFullFtpPath(client, path, false);
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Parse raw file from server into a file object, using the currently active parser.
        /// </summary>
        public FtpListItem ParseSingleLine(string path, string file, List <FtpCapability> caps, bool isMachineList)
        {
            FtpListItem result = null;

            // force machine listing if it is
            if (isMachineList)
            {
                result = FtpMachineListParser.Parse(file, caps, client);
            }
            else
            {
                // use custom parser if given
                if (CurrentParser == FtpParser.Custom && client.ListingCustomParser != null)
                {
                    result = client.ListingCustomParser(file, caps, client);
                }
                else
                {
                    if (IsWrongParser())
                    {
                        ValidateParser(new[] { file });
                    }

                    // use one of the in-built parsers
                    switch (CurrentParser)
                    {
                    case FtpParser.Machine:
                        result = FtpMachineListParser.Parse(file, caps, client);
                        break;

                    case FtpParser.Windows:
                        result = FtpWindowsParser.Parse(client, file);
                        break;

                    case FtpParser.Unix:
                        result = FtpUnixParser.Parse(client, file);
                        break;

                    case FtpParser.UnixAlt:
                        result = FtpUnixParser.ParseUnixAlt(client, file);
                        break;

                    case FtpParser.VMS:
                        result = FtpVMSParser.Parse(client, file);
                        break;

                    case FtpParser.IBM:
                        result = FtpIBMParser.Parse(client, file);
                        break;

                    case FtpParser.NonStop:
                        result = FtpNonStopParser.Parse(client, file);
                        break;
                    }
                }
            }

            // if parsed file successfully
            if (result != null)
            {
                // process created date into the timezone required
                result.RawCreated = result.Created;
                if (result.Created != DateTime.MinValue)
                {
                    result.Created = client.ConvertDate(result.Created);
                }

                // process modified date into the timezone required
                result.RawModified = result.Modified;
                if (result.Modified != DateTime.MinValue)
                {
                    result.Modified = client.ConvertDate(result.Modified);
                }

                // calc absolute file paths
                result.CalculateFullFtpPath(client, path, false);
            }

            return(result);
        }