Пример #1
0
        /// <summary>
        /// Validate if the current parser is correct, or if another parser seems more appropriate.
        /// </summary>
        private void ValidateParser(string[] files)
        {
            if (IsWrongParser())
            {
                // by default use the UNIX parser, if none detected
                if (DetectedParser == FtpParser.Auto)
                {
                    DetectedParser = FtpParser.Unix;
                }

                if (CurrentParser == FtpParser.Auto)
                {
                    CurrentParser = DetectedParser;
                }

                // if machine listings not supported, switch to UNIX parser
                if (IsWrongMachineListing())
                {
                    CurrentParser = DetectedParser;
                }

                // use the initially set parser (from SYST)
                if (IsParserValid(CurrentParser, files))
                {
                    client.LogStatus(FtpTraceLevel.Verbose, "Confirmed format " + CurrentParser.ToString());
                    ParserConfirmed = true;
                    return;
                }

                foreach (var p in parsers)
                {
                    if (IsParserValid(p, files))
                    {
                        CurrentParser = p;
                        client.LogStatus(FtpTraceLevel.Verbose, "Detected format " + CurrentParser.ToString());
                        ParserConfirmed = true;
                        return;
                    }
                }

                CurrentParser = FtpParser.Unix;
                client.LogStatus(FtpTraceLevel.Verbose, "Could not detect format. Using default " + CurrentParser.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Try to auto-detect which parser is suitable given a system string.
        /// </summary>
        public void Init(FtpOperatingSystem system, FtpParser forcedParser = FtpParser.Auto)
        {
            ParserConfirmed = false;

            if (forcedParser != FtpParser.Auto)
            {
                // use the parser that the server handler specified
                CurrentParser = forcedParser;
            }
            else
            {
                if (system == FtpOperatingSystem.Windows)
                {
                    CurrentParser = FtpParser.Windows;
                }
                else if (system == FtpOperatingSystem.Unix || system == FtpOperatingSystem.SunOS)
                {
                    CurrentParser = FtpParser.Unix;
                }
                else if (system == FtpOperatingSystem.VMS)
                {
                    CurrentParser = FtpParser.VMS;
                }
                else if (system == FtpOperatingSystem.IBMzOS)
                {
                    CurrentParser = FtpParser.IBMzOS;
                }
                else if (system == FtpOperatingSystem.IBMOS400)
                {
                    CurrentParser = FtpParser.IBMOS400;
                }
                else
                {
                    CurrentParser = FtpParser.Unix;
                    client.LogStatus(FtpTraceLevel.Warn, "Cannot auto-detect listing parser for system '" + system + "', using Unix parser");
                }
            }

            DetectedParser = CurrentParser;

            client.LogStatus(FtpTraceLevel.Verbose, "Listing parser set to: " + DetectedParser.ToString());
        }