コード例 #1
0
        private static void GetSettings()
        {
            Console.WriteLine("\n-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port)
            {
                Log = DebugLog
            })
            {
                var stopWatch = Stopwatch2.StartNew();

                fileZillaApi.Connect(ServerPassword);
                var settings = fileZillaApi.GetSettings();
                Console.WriteLine("Settings retrieved in {0}.", stopWatch.GetDelta());
                int optionNumber = 0;
                foreach (var o in settings.Options)
                {
                    Console.WriteLine("  {0} = {1}",
                                      o.Label,
                                      o.OptionType == OptionType.Text
                            ? o.TextValue
                            : o.NumericValue.ToString()
                                      );
                    optionNumber++;
                }
            }
        }
コード例 #2
0
        private static void GetSettings()
        {
            Console.WriteLine("-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port) { Log = new DebugTextWriter() })
            {
                var stopWatch = Stopwatch2.StartNew();

                fileZillaApi.Connect(ServerPassword);
                var settings = fileZillaApi.GetSettings();
                Console.WriteLine("Settings retrieved in {0}.", stopWatch.GetDelta());
                int optionNumber = 0;
                foreach (var o in settings.Options)
                {
                    Console.WriteLine("  {0} = {1}",
                        o.Label,
                        o.OptionType == OptionType.Text
                            ? o.TextValue
                            : o.NumericValue.ToString()
                        );
                    optionNumber++;
                }
            }
        }
コード例 #3
0
        private static void SetSettings()
        {
            Console.WriteLine("\n-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port)
            {
                Log = DebugLog
            })
            {
                var stopWatch = Stopwatch2.StartNew();

                fileZillaApi.Connect(ServerPassword);
                var settings = fileZillaApi.GetSettings();
                Console.WriteLine("Settings retrieved in {0}.", stopWatch.GetDelta());

                // Select option to modify
                var option = settings.GetOption(OptionId.WELCOMEMESSAGE);

                // Modify
                string       originalTextValue = option.TextValue;
                const string newMessage        = "Hello world";
                option.TextValue = newMessage;

                // Save
                if (!fileZillaApi.SetSettings(settings))
                {
                    throw new Exception("Uh uh");
                }
                var settings2 = fileZillaApi.GetSettings();

                // Verify
                if (settings.Options.Count() != settings2.Options.Count())
                {
                    throw new Exception("Uh uh");
                }
                for (int i = 0; i < settings.Options.Count(); i++)
                {
                    if (settings.Options[i].Label != settings2.Options[i].Label)
                    {
                        throw new Exception("Uh uh");
                    }
                    if (settings.Options[i].NotRemotelyChangeable != settings2.Options[i].NotRemotelyChangeable)
                    {
                        throw new Exception("Uh uh");
                    }
                    if (settings.Options[i].OptionType != settings2.Options[i].OptionType)
                    {
                        throw new Exception("Uh uh");
                    }
                    if (settings.Options[i].NumericValue != settings2.Options[i].NumericValue)
                    {
                        // Numeric value of "No Transfer Timeout" is bumped up to 600 by the server. Ignore that.
                        if (!(settings.Options[i].Label == "No Transfer Timeout" && settings.Options[i].NumericValue < 600 && settings2.Options[i].NumericValue == 600))
                        {
                            throw new Exception("Uh uh");
                        }
                    }

                    if (settings.Options[i].TextValue != settings2.Options[i].TextValue)
                    {
                        // Admin Password is sent as "*" when not set
                        if (!(settings.Options[i].Label == "Admin Password" && settings.Options[i].TextValue == "*" && settings2.Options[i].TextValue == null))
                        {
                            throw new Exception("Uh uh");
                        }
                    }
                }

                // Restore
                settings.GetOption(OptionId.WELCOMEMESSAGE).TextValue = originalTextValue;
                fileZillaApi.SetSettings(settings);
            }
        }
コード例 #4
0
        private static void SetSettings()
        {
            Console.WriteLine("-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port) { Log = new DebugTextWriter() })
            {
                var stopWatch = Stopwatch2.StartNew();

                fileZillaApi.Connect(ServerPassword);
                var settings = fileZillaApi.GetSettings();
                Console.WriteLine("Settings retrieved in {0}.", stopWatch.GetDelta());

                // Select option to modify
                var option = settings.GetOption(OptionId.WELCOMEMESSAGE);

                // Modify
                string originalTextValue = option.TextValue;
                const string newMessage = "Hello world";
                option.TextValue = newMessage;

                // Save
                if (!fileZillaApi.SetSettings(settings)) throw new Exception("Uh uh");
                var settings2 = fileZillaApi.GetSettings();

                // Verify 
                if (settings.Options.Count() != settings2.Options.Count()) throw new Exception("Uh uh");
                for (int i = 0; i < settings.Options.Count(); i++)
                {
                    if (settings.Options[i].Label != settings2.Options[i].Label) throw new Exception("Uh uh");
                    if (settings.Options[i].NotRemotelyChangeable != settings2.Options[i].NotRemotelyChangeable) throw new Exception("Uh uh");
                    if (settings.Options[i].OptionType != settings2.Options[i].OptionType) throw new Exception("Uh uh");
                    if (settings.Options[i].NumericValue != settings2.Options[i].NumericValue)
                    {
                        // Numeric value of "No Transfer Timeout" is bumped up to 600 by the server. Ignore that.
                        if (!(settings.Options[i].Label == "No Transfer Timeout" && settings.Options[i].NumericValue < 600 && settings2.Options[i].NumericValue == 600))
                            throw new Exception("Uh uh");
                    }

                    if (settings.Options[i].TextValue != settings2.Options[i].TextValue )
                    {
                        // Admin Password is sent as "*" when not set
                        if (!(settings.Options[i].Label == "Admin Password" && settings.Options[i].TextValue == "*" && settings2.Options[i].TextValue == null)) 
                            throw new Exception("Uh uh");
                    }                        
                }

                // Restore 
                settings.GetOption(OptionId.WELCOMEMESSAGE).TextValue = originalTextValue;
                fileZillaApi.SetSettings(settings);
            }
        }