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());
            }
        }
Beispiel #2
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());
                }
            }
        }
Beispiel #3
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));
            }
        }
Beispiel #4
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));
            }
        }
Beispiel #6
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)
            {
            }
        }
        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());
            }
        }
        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());
            }
        }
        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());
            }
        }
        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());
            }
        }
        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());
            }
        }