Ejemplo n.º 1
0
        private static void ReuseConnection()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);

                // Get to _socket variable using reflection.
                var field  = typeof(SocketCommunication).GetField("_socket", BindingFlags.NonPublic | BindingFlags.Instance);
                var socket = (Socket)field.GetValue(fileZillaApi);
                // Disconnect socket to simulate that connection has been broken.
                socket.Disconnect(false);

                if (fileZillaApi.IsConnected)
                {
                    throw new ApplicationException("Hmm, it is supposed to be disconnected");
                }
                fileZillaApi.Connect(ServerPassword);
                serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);
            }
        }
Ejemplo n.º 2
0
        private static void SetServerState()
        {
            Console.WriteLine("-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port) { Log = new DebugTextWriter() })
            {
                fileZillaApi.Connect(ServerPassword);
                var serverState = fileZillaApi.GetServerState();
                Console.WriteLine("State is {0}", serverState);

                // Go offiline
                serverState = fileZillaApi.SetServerState(ServerState.GoOfflineNow);
                Console.WriteLine("GoOfflineNow State is {0}", serverState);
                Thread.Sleep(TimeSpan.FromSeconds(5));
                serverState = fileZillaApi.GetServerState();
                Console.WriteLine("State is {0}", serverState);

                // Go online
                serverState = fileZillaApi.SetServerState(ServerState.Online);
                Console.WriteLine("State is {0}", serverState);

                // Lock server
                serverState = fileZillaApi.SetServerState(ServerState.Online | ServerState.Locked);
                Console.WriteLine("Lock State is {0}", serverState);

                // Unlock
                serverState = fileZillaApi.SetServerState(ServerState.Online);
                Console.WriteLine("State is {0}", serverState);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Kick first connection
        /// </summary>
        private static void KickFirstConnection()
        {
            Console.WriteLine("\n-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port)
            {
                Log = DebugLog
            })
            {
                fileZillaApi.Connect(ServerPassword);

                var connections = fileZillaApi.GetConnections();
                if (connections.Any())
                {
                    if (fileZillaApi.Kick(connections.First().ConnectionId))
                    {
                        Console.WriteLine("Connection was kicked");
                    }
                    else
                    {
                        Console.WriteLine("Connection was NOT kicked");
                    }
                }
                else
                {
                    Console.WriteLine("No connections available");
                }
            }
        }
Ejemplo n.º 4
0
        private static void DeleteLotsOfUsersAndGroups()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);

                var accountSettings = fileZillaApi.GetAccountSettings();
                Console.WriteLine("Account settings with {0} groups and {1} users fetched in {2}.",
                                  accountSettings.Groups.Count,
                                  accountSettings.Users.Count,
                                  stopWatch.GetDelta());

                accountSettings.Users.RemoveAll(x => x.UserName.StartsWith(UserName));
                accountSettings.Groups.RemoveAll(x => x.GroupName.StartsWith(GroupName));

                fileZillaApi.SetAccountSettings(accountSettings);
                Console.WriteLine("Finished saving account settings in {0}.", stopWatch.GetDelta());
            }
        }
Ejemplo n.º 5
0
        private static void SetServerState()
        {
            Console.WriteLine("\n-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port)
            {
                Log = DebugLog
            })
            {
                fileZillaApi.Connect(ServerPassword);
                var serverState = fileZillaApi.GetServerState();
                Console.WriteLine("State is {0}", serverState);

                // Go offiline
                serverState = fileZillaApi.SetServerState(ServerState.GoOfflineNow);
                Console.WriteLine("GoOfflineNow State is {0}", serverState);
                Thread.Sleep(TimeSpan.FromSeconds(5));
                serverState = fileZillaApi.GetServerState();
                Console.WriteLine("State is {0}", serverState);

                // Go online
                serverState = fileZillaApi.SetServerState(ServerState.Online);
                Console.WriteLine("State is {0}", serverState);

                // Lock server
                serverState = fileZillaApi.SetServerState(ServerState.Online | ServerState.Locked);
                Console.WriteLine("Lock State is {0}", serverState);

                // Unlock
                serverState = fileZillaApi.SetServerState(ServerState.Online);
                Console.WriteLine("State is {0}", serverState);
            }
        }
Ejemplo n.º 6
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++;
                }
            }
        }
Ejemplo n.º 7
0
        private static void ChangeExistingUser()
        {
            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 accountSettings = fileZillaApi.GetAccountSettings();
                Console.WriteLine("Account settings with {0} groups and {1} users fetched in {2}.",
                                  accountSettings.Groups.Count,
                                  accountSettings.Users.Count,
                                  stopWatch.GetDelta());

                // Find user using LINQ.
                var existingUser = accountSettings.Users.FirstOrDefault(x => x.UserName == ExampleUserName);

                // Did we find a user with the provided user name?
                if (existingUser != null)
                {
                    // Modify all aspects of the user.
                    existingUser.AssignPassword("NewPassword", fileZillaApi.ProtocolVersion);

                    // Save the changed user
                    Console.WriteLine("Save all settings including the modified user");
                    fileZillaApi.SetAccountSettings(accountSettings);
                    Console.WriteLine("Finished saving account settings in {0}.", stopWatch.GetDelta());
                }
            }
        }
Ejemplo n.º 8
0
        public void PasswordTest()
        {
            const string UserName = "******";
            const string Password = "******";

            using (IFileZillaApi fileZillaApi = new FileZillaApi()
            {
                Log = Console.Out
            })
            {
                fileZillaApi.Connect("");

                var accountSettings = fileZillaApi.GetAccountSettings();

                var user = accountSettings.Users.Find(x => x.UserName == UserName);
                Assert.That(user, Is.Not.Null);

                Console.WriteLine("User.Password({0}):{1}", user.Password.Length, user.Password);
                Console.WriteLine("Salt({0}):{1}", user.Salt.Length, user.Salt);

                var password = User.HashPasswordSha512(Password, user.Salt);
                Console.WriteLine("Calculated password ({0}):{1}", password.Length, password);

                Assert.That(password, Is.EqualTo(user.Password));
            }
        }
Ejemplo n.º 9
0
        private static void GetServerState()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);
            }
        }
Ejemplo n.º 10
0
        public void UserPasswordTest()
        {
            const string UserName = "******";
            const string Password = "******";

            using (IFileZillaApi fileZillaApi = new FileZillaApi()
            {
                Log = Console.Out
            })
            {
                fileZillaApi.Connect("");

                var accountSettings = fileZillaApi.GetAccountSettings();

                var user = new User
                {
                    UserName      = UserName,
                    SharedFolders = new List <SharedFolder>()
                    {
                        new SharedFolder()
                        {
                            Directory    = @"C:\Foo\Bar",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.FileWrite | AccessRights.IsHome
                        }
                    }
                };
                user.AssignPassword(Password, fileZillaApi.ProtocolVersion);

                Console.WriteLine("User.Password({0}):{1}", user.Password.Length, user.Password);
                Console.WriteLine("Salt({0}):{1}", user.Salt.Length, user.Salt);

                accountSettings.Users.RemoveAll(x => x.UserName == UserName);
                accountSettings.Users.Add(user);
                fileZillaApi.SetAccountSettings(accountSettings);

                accountSettings = fileZillaApi.GetAccountSettings();

                user = accountSettings.Users.Find(x => x.UserName == UserName);
                Assert.That(user, Is.Not.Null);

                Console.WriteLine("User.Password({0}):{1}", user.Password.Length, user.Password);
                Console.WriteLine("Salt({0}):{1}", user.Salt.Length, user.Salt);

                var password = User.HashPasswordSha512(Password, user.Salt);
                Console.WriteLine("Calculated password ({0}):{1}", password.Length, password);

                Assert.That(password, Is.EqualTo(user.Password));
            }
        }
Ejemplo n.º 11
0
        private static void GetServerState()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);
            }
        }
Ejemplo n.º 12
0
 static void Main(string[] args)
 {
     Console.WriteLine("Author: Hzllaga");
     Console.WriteLine("Github: https://github.com/Hzllaga");
     Console.WriteLine();
     Parser.Default.ParseArguments <Options>(args)
     .WithParsed <Options>(o =>
     {
         var fileZillaApi = new FileZillaApi(IPAddress.Parse(o.Target), o.Port);
         try
         {
             fileZillaApi.Connect(o.Password);
         }
         catch (Exception e)
         {
             Console.Write("[-] Connect error: ");
             Console.WriteLine(e.Message);
             return;
         }
         Console.WriteLine("[+] Connected.");
         var accountSettings = fileZillaApi.GetAccountSettings();
         var user            = new User
         {
             UserName      = o.SetUsername,
             SharedFolders = new List <SharedFolder>()
             {
                 new SharedFolder()
                 {
                     Directory    = o.SetDir,
                     AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.FileWrite | AccessRights.IsHome | AccessRights.FileAppend | AccessRights.AutoCreate | AccessRights.DirCreate | AccessRights.DirDelete | AccessRights.FileDelete
                 }
             }
         };
         user.AssignPassword(o.SetPassword, fileZillaApi.ProtocolVersion);
         accountSettings.Users.Add(user);
         try
         {
             fileZillaApi.SetAccountSettings(accountSettings);
         }
         catch (Exception e)
         {
             Console.Write("[-] Create error: ");
             Console.WriteLine(e.Message);
             return;
         }
         Console.WriteLine("[+] Done, Enjoy!");
     });
 }
        public void UserPasswordTest()
        {
            const string UserName = "******";
            const string Password = "******";

            using (IFileZillaApi fileZillaApi = new FileZillaApi() { Log = Console.Out })
            {
                fileZillaApi.Connect("");

                var accountSettings = fileZillaApi.GetAccountSettings();

                var user = new User
                {
                    UserName = UserName,
                    SharedFolders = new List<SharedFolder>()
                    {
                        new SharedFolder()
                        {
                            Directory = @"C:\Foo\Bar",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.FileWrite | AccessRights.IsHome
                        }
                    }
                };
                user.AssignPassword(Password, fileZillaApi.ProtocolVersion);

                Console.WriteLine("User.Password({0}):{1}", user.Password.Length, user.Password);
                Console.WriteLine("Salt({0}):{1}", user.Salt.Length, user.Salt);

                accountSettings.Users.RemoveAll(x => x.UserName == UserName);
                accountSettings.Users.Add(user);
                fileZillaApi.SetAccountSettings(accountSettings);

                accountSettings = fileZillaApi.GetAccountSettings();

                user = accountSettings.Users.Find(x => x.UserName == UserName);
                Assert.That(user, Is.Not.Null);

                Console.WriteLine("User.Password({0}):{1}", user.Password.Length, user.Password);
                Console.WriteLine("Salt({0}):{1}", user.Salt.Length, user.Salt);

                var password = User.HashPasswordSha512(Password, user.Salt);
                Console.WriteLine("Calculated password ({0}):{1}", password.Length, password);

                Assert.That(password, Is.EqualTo(user.Password));
            }
        }
        public void PasswordTest()
        {
            const string UserName = "******";
            const string Password = "******";

            using (IFileZillaApi fileZillaApi = new FileZillaApi() {Log = Console.Out})
            {
                fileZillaApi.Connect("");

                var accountSettings = fileZillaApi.GetAccountSettings();

                var user = accountSettings.Users.Find(x => x.UserName == UserName);
                Assert.That(user, Is.Not.Null);

                Console.WriteLine("User.Password({0}):{1}", user.Password.Length, user.Password);
                Console.WriteLine("Salt({0}):{1}", user.Salt.Length, user.Salt);

                var password = User.HashPasswordSha512(Password, user.Salt);
                Console.WriteLine("Calculated password ({0}):{1}", password.Length, password);

                Assert.That(password, Is.EqualTo(user.Password));
            }
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            try
            {
                string path = ConfigurationSettings.AppSettings["pathCreateFolder"];
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
                Directory.CreateDirectory(path);

                var fileZillaApi = new FileZillaApi();
                fileZillaApi.Connect("");
                var accountSettings = fileZillaApi.GetAccountSettings();

                var user = new User
                {
                    UserName      = "******",
                    SharedFolders = new List <SharedFolder>()
                    {
                        new SharedFolder()
                        {
                            Directory    = path,
                            AccessRights = AccessRights.DirList | AccessRights.DirCreate | AccessRights.DirSubdirs | AccessRights.DirDelete |
                                           AccessRights.FileRead | AccessRights.FileWrite | AccessRights.FileDelete | AccessRights.FileAppend |
                                           AccessRights.IsHome
                        }
                    }
                };
                user.AssignPassword("admin", fileZillaApi.ProtocolVersion);
                accountSettings.Users.Add(user);
                fileZillaApi.SetAccountSettings(accountSettings);
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Kick first connection
        /// </summary>
        private static void KickFirstConnection()
        {
            Console.WriteLine("-- {0} --", MethodBase.GetCurrentMethod().Name);
            using (IFileZillaApi fileZillaApi = new FileZillaApi(IPAddress.Parse(Ip), Port) { Log = new DebugTextWriter() })
            {
                fileZillaApi.Connect(ServerPassword);

                var connections = fileZillaApi.GetConnections();
                if (connections.Any())
                {
                    if (fileZillaApi.Kick(connections.First().ConnectionId))
                        Console.WriteLine("Connection was kicked");
                    else
                        Console.WriteLine("Connection was NOT kicked");
                }
                else
                    Console.WriteLine("No connections available");
            }
        }
Ejemplo n.º 18
0
        private static void CreateUserAndGroup()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);

                var accountSettings = fileZillaApi.GetAccountSettings();
                Console.WriteLine("Account settings with {0} groups and {1} users fetched in {2}.",
                    accountSettings.Groups.Count,
                    accountSettings.Users.Count,
                    stopWatch.GetDelta());

                var group = new Group()
                {
                    GroupName = GroupName,
                    SharedFolders = new List<SharedFolder>()
                    {
                        new SharedFolder()
                        {
                            Directory = @"C:\Group\Shared",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.IsHome
                        },
                             new SharedFolder()
                        {
                            Directory = @"C:\foo\bar",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead
}
                    },
                    AllowedIPs = new List<string>() { "127.0.0.1", "10.10.10.10", "42.42.42.42", "::1" },
                    DisallowedIPs = new List<string>() { "172.0.0.0" },
                    ForceSsl = true,
                    Comment = "The quick brown fox jumps over the lazy dog",
                    BypassUserLimit = TriState.No,
                };
                accountSettings.Groups.RemoveAll(x => x.GroupName == GroupName);
                accountSettings.Groups.Add(@group);

                var user = new User
                {
                    GroupName = GroupName, // Reference to group
                    UserName = UserName,
                    Password = User.HashPassword("test42"),
                    SharedFolders = new List<SharedFolder>()
                    {
                        new SharedFolder()
                        {
                            Directory = @"C:\Hello\World",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.IsHome
                        },
                        new SharedFolder()
                        {
                            Directory = @"C:\foo\bar",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead
                        }
                    }
                };
                accountSettings.Users.RemoveAll(x => x.UserName == UserName);
                accountSettings.Users.Add(user);

                Console.WriteLine("Created {0} groups and {1} users in {2}.",
                    1,
                    1,
                    stopWatch.GetDelta());

                fileZillaApi.SetAccountSettings(accountSettings);
                Console.WriteLine("Finished saving account settings in {0}.", stopWatch.GetDelta());
            }
        }
Ejemplo n.º 19
0
        private static void CreateLotsOfUsersAndGroups()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);
                var accountSettings = fileZillaApi.GetAccountSettings();
                Console.WriteLine("Account settings with {0} groups and {1} users fetched in {2}.",
                    accountSettings.Groups.Count,
                    accountSettings.Users.Count,
                    stopWatch.GetDelta());

                accountSettings.Groups.RemoveAll(x => x.GroupName.StartsWith(GroupName));
                accountSettings.Users.RemoveAll(x => x.UserName.StartsWith(UserName));

                for (var i = 0; i < MaxGroups; i++)
                {
                    var group = new Group()
                    {
                        GroupName = GroupName + i,
                        SharedFolders = new List<SharedFolder>()
                        {
                            new SharedFolder()
                            {
                                Directory = @"C:\Group" + i + @"\Shared",
                                AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.IsHome
                            }
                        },
                    };

                    accountSettings.Groups.Add(group);
                }

                var maxUsers = fileZillaApi.ProtocolVersion < ProtocolVersions.User16M ? MaxUsers64K : MaxUsers16M;
                for (var i = 0; i < maxUsers; i++)
                {
                    var user = new User
                    {
                        GroupName = GroupName + (i % MaxGroups), // Reference to group
                        UserName = UserName + i,
                        Password = User.HashPassword("LonglongPasswordwithnumber" + i),
                        SharedFolders = new List<SharedFolder>()
                        {
                            new SharedFolder()
                            {
                                Directory = @"C:\User" + i + @"\Private",
                                AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.IsHome
                            }
                        },
                    };
                    accountSettings.Users.Add(user);
                }

                Console.WriteLine("Created {0} groups and {1} users in {2}.",
                    MaxGroups,
                    maxUsers,
                    stopWatch.GetDelta());

                fileZillaApi.SetAccountSettings(accountSettings);
                Console.WriteLine("Finished saving account settings in {0}.", stopWatch.GetDelta());
            }
        }
Ejemplo n.º 20
0
        private static void CreateLotsOfUsersAndGroups()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);
                var accountSettings = fileZillaApi.GetAccountSettings();
                Console.WriteLine("Account settings with {0} groups and {1} users fetched in {2}.",
                                  accountSettings.Groups.Count,
                                  accountSettings.Users.Count,
                                  stopWatch.GetDelta());

                accountSettings.Groups.RemoveAll(x => x.GroupName.StartsWith(GroupName));
                accountSettings.Users.RemoveAll(x => x.UserName.StartsWith(UserName));

                for (var i = 0; i < MaxGroups; i++)
                {
                    var group = new Group()
                    {
                        GroupName     = GroupName + i,
                        SharedFolders = new List <SharedFolder>()
                        {
                            new SharedFolder()
                            {
                                Directory    = @"C:\Group" + i + @"\Shared",
                                AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.IsHome
                            }
                        },
                    };

                    accountSettings.Groups.Add(group);
                }

                var maxUsers = fileZillaApi.ProtocolVersion < ProtocolVersions.User16M ? MaxUsers64K : MaxUsers16M;
                for (var i = 0; i < maxUsers; i++)
                {
                    var user = new User
                    {
                        GroupName     = GroupName + (i % MaxGroups), // Reference to group
                        UserName      = UserName + i,
                        SharedFolders = new List <SharedFolder>()
                        {
                            new SharedFolder()
                            {
                                Directory    = @"C:\User" + i + @"\Private",
                                AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.IsHome
                            }
                        },
                    };
                    user.AssignPassword("LonglongPasswordwithnumber" + i, fileZillaApi.ProtocolVersion);

                    accountSettings.Users.Add(user);
                }

                Console.WriteLine("Created {0} groups and {1} users in {2}.",
                                  MaxGroups,
                                  maxUsers,
                                  stopWatch.GetDelta());

                fileZillaApi.SetAccountSettings(accountSettings);
                Console.WriteLine("Finished saving account settings in {0}.", stopWatch.GetDelta());
            }
        }
Ejemplo n.º 21
0
        private static void CreateUserAndGroup()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);

                var accountSettings = fileZillaApi.GetAccountSettings();
                Console.WriteLine("Account settings with {0} groups and {1} users fetched in {2}.",
                                  accountSettings.Groups.Count,
                                  accountSettings.Users.Count,
                                  stopWatch.GetDelta());

                var group = new Group()
                {
                    GroupName     = GroupName,
                    SharedFolders = new List <SharedFolder>()
                    {
                        new SharedFolder()
                        {
                            Directory    = @"C:\Group\Shared",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.IsHome
                        },
                        new SharedFolder()
                        {
                            Directory    = @"C:\foo\bar",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead
                        }
                    },
                    AllowedIPs = new List <string>()
                    {
                        "127.0.0.1", "10.10.10.10", "42.42.42.42", "::1"
                    },
                    DisallowedIPs = new List <string>()
                    {
                        "172.0.0.0"
                    },
                    ForceSsl        = true,
                    Comment         = "The quick brown fox jumps over the lazy dog",
                    BypassUserLimit = TriState.No,
                };
                accountSettings.Groups.RemoveAll(x => x.GroupName == GroupName);
                accountSettings.Groups.Add(@group);

                var user = new User
                {
                    GroupName     = GroupName, // Reference to group
                    UserName      = UserName,
                    SharedFolders = new List <SharedFolder>()
                    {
                        new SharedFolder()
                        {
                            Directory    = @"C:\UserX\Home",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead | AccessRights.FileWrite | AccessRights.IsHome
                        },
                        new SharedFolder()
                        {
                            Directory    = @"C:\Shared\foo\bar",
                            AccessRights = AccessRights.DirList | AccessRights.DirSubdirs | AccessRights.FileRead
                        }
                    }
                };
                user.AssignPassword("test42", fileZillaApi.ProtocolVersion);
                accountSettings.Users.RemoveAll(x => x.UserName == UserName);
                accountSettings.Users.Add(user);

                Console.WriteLine("Created {0} groups and {1} users in {2}.",
                                  1,
                                  1,
                                  stopWatch.GetDelta());

                fileZillaApi.SetAccountSettings(accountSettings);
                Console.WriteLine("Finished saving account settings in {0}.", stopWatch.GetDelta());
            }
        }
Ejemplo n.º 22
0
        private static void DeleteLotsOfUsersAndGroups()
        {
            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 serverState = fileZillaApi.GetServerState();
                Console.WriteLine("Connected in {0}. State is {1}", stopWatch.GetDelta(), serverState);

                var accountSettings = fileZillaApi.GetAccountSettings();
                Console.WriteLine("Account settings with {0} groups and {1} users fetched in {2}.",
                    accountSettings.Groups.Count,
                    accountSettings.Users.Count,
                    stopWatch.GetDelta());

                accountSettings.Users.RemoveAll(x => x.UserName.StartsWith(UserName));
                accountSettings.Groups.RemoveAll(x => x.GroupName.StartsWith(GroupName));

                fileZillaApi.SetAccountSettings(accountSettings);
                Console.WriteLine("Finished saving account settings in {0}.", stopWatch.GetDelta());
            }
        }
Ejemplo n.º 23
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);
            }
        }
Ejemplo n.º 24
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++;
                }
            }
        }