Knowledge Base

Enter search queries below or use the tag links to the right to browse the knowledge base by category (Show All Tags).


How to create Robo-FTP Server's users programmatically

Sometimes you may need to create or delete Robo-FTP Server users programmatically. This can be done using COM because the server's configuration management is exposed as an out of process COM server. Here I will provide an example of creating and deleting a user in C# using COM interop. The following steps must be done on a machine with Robo-FTP Server installed.

  1. Create a new C# Console Project
  2. Add a reference to RoboFTPServer configuration library
    a. Right click on references and select add reference.
    b. Choose COM and scroll down until you see RoboFTPServer Type Library
  3. Add a using line of the form using RoboFTPServer
  4. Insert the following code into your main function...

        try
        {
            RSGlobalConfig config = new RSGlobalConfigClass();
            if(args.Length == 3 && args[0] == "create")
            {
                RSUserConfig user1 = new RSUserConfigClass();
                RSUserConfig user2 = new RSUserConfigClass();
                user1.Name = args[1];
                user1.Home = args[1];
                user1.Password = args[2];
                user1.Auth = UserAuth.AuthEither;
                user1.Permissions = (int)RoboPermissions.PermissionsAll;
                user2.Name = args[1];
                user2.Home = args[1];
                user2.Password = args[2];
                user2.Auth = UserAuth.AuthEither;
                user2.Permissions = (int)RoboPermissions.PermissionsAll;
                config.Servers[1].Users.Add(user1); //add user to ftp server
                config.Servers[2].Users.Add(user2); //add user to sftp server
                config.SaveConfig();
                Console.WriteLine("User " + args[1] + " created.");
            }
            else if (args.Length == 2 && args[0] == "delete")
            {
                bool found = false;
                for(int i = 1; i <=2; i++)
                {
                    try
                    {
                        config.Servers[i].BootUser(args[1]);
                        config.Servers[i].Users.Remove(args[1]);
                        found = true;
                    }
                    catch
                    {
                    }
                }
                if (!found)
                    Console.WriteLine("User " + args[1] + " not found!");
                else
                {
                    config.SaveConfig();
                    Console.WriteLine("User " + args[1] + " deleted.");
                }
            }
            else
            {
                Console.WriteLine("Usage: CreateOrDeleteUser create username password");
                Console.WriteLine("       CreateOrDeleteUser delete username");
            }
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    

Article last updated: 2021-01-22

Tags: Robo-FTP Server, COM, Configuration, Server Console