Knowledge Base

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


Automating user account creation in Robo-FTP Server with C#.

To build a project that interacts with Robo-FTP Server, you will first need to install Robo-FTP Server on the relevant development machine so that its .COM Type Library can be accessed. Once that is done, create a new C# project. We recommended you choose .NET Framework 4.0 for ease of deployment, since that is the same .NET version used by Robo-FTP Server itself.

After the project has been created, you will need to add a reference to the "RoboFTPServer" .COM Type Library, We also recommend adding a reference to the "System.Management" assembly, for handling directory permissions.

Before proceeding, it will be helpful to have an understanding of the relationship between a user configuration (hereafter referred to RSUserConfig) and a server configuration (RSServerConfig). An RSUserConfig object contains data regarding a user, and an RSServerConfig object contains data regarding a server. Currently there are two main RSServerConfig objects: one corresponding to a shared FTP(S) and HTTP(S) configuration, and a second corresponding to an SFTP-only configuration. We will refer to the former as "CRSFTPServerConfig" and the latter as "CRSSFTPServerConfig". These can be accessed from the global configuration object, as follows:

RoboFTPServer.RSGlobalConfig CRSGlobalConfig = new RoboFTPServer.RSGlobalConfig();
RoboFTPServer.RSServerConfig CRSFTPServerConfig = CRSGlobalConfig.Servers[1];
RoboFTPServer.RSServerConfig CRSSFTPServerConfig = CRSGlobalConfig.Servers[2];

While at the UI level, an individual user appears as a single entity, internally, each RSServerConfig stores a separate set of RSUserConfig objects. Hence, if a new user "bob" is assigned to "Both" FTP and SFTP Connection Types from the Robo-FTP Server Console, two separate RSUserConfig objects are created with overlapping settings and assigned separately to each RSServerConfig object.

An RSUserConfig object contains many different properties. Among the most important are:

"Name" (username),
"Domain" (Windows domain, when using "Windows Authentication" or "Windows group authentication"),
"Home" (home directory),
"Password", and
"Auth" (authentication type).

As for the "Auth" authentication types, the most commonly used are:

AuthEither (requires a password OR public key login),
AuthBoth (requires both a password AND public key login),
AuthNTLM ("Windows Authentication"),
AuthNTLMGroup ("Windows Group Authentication"), and
AuthAnonymous (for anonymous access).

With NTLM-based authentication, other properties may need to be specified, such as the "Domain" and "WindowsGroupPath" properties. For SFTP users, one may wish to additionally assign an SFTP public key for password-less authentication:

string sshPubkeyStr = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDO0BF4lWXAmFXjIkan" +
                      "qMo0/rjlL/fiQ8LClAqmx7Mj6a/Df09jE9gvdKzGQwmXeWBgY0BHrCml" +
                      "RAZ/HVBtyyuk4+V9qGfyZWQVv8YqgjDx+F6mQracjqKUSVzle2FDDxEg" +
                      "Qmlcpdt3e2mYYVxcCjB3WMJB5GBVZMmxp2j2EMHUhLpyuwc+fzZzmc/M" +
                      "WnCZbdFA6V0+Ylmyzqoqg+HUiy3SewJ9O69GEDOQx7tsxcdQ7Cm54baC" +
                      "jKmioJVJRqppCSHfWLAm7RW5F4TZEZQyYsSgQmktAiV4E5k9OXkEPgAk" +
                      "wwQUQS8RSu3RZzRAGwjKw7JMFw1I7bPrcxMJD78rJUhp user@COMPUTER";
myUserConfig.PublicKeys.Add(sshPubkeyStr);

Robo-FTP Server allows users to be granted 8 separate permissions, which are stored as a bitfield inside the "Permissions" property. Consider the following example on how to grant each permission to a user:

int nPermissions = 0;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionDeleteDir;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionDeleteFile;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionDownload;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionList;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionCreateDir;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionModify;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionUpload;
nPermissions |= (int)RoboFTPServer.RoboPermissions.PermissionPost;
myUserConfig.Permissions = nPermissions;

A user's home folder is specified through the "Home" property. This can be either an absolute path, or a relative path. In the case of a relative path, it must be relative to the server root, and the associated string must begin with the special $SERVERROOT variable, as in the following example:

string userName = "bobisyouruncle";
myUserConfig.Home = "$SERVERROOT\" + userName;

Note that the Robo-FTP Server service must have traverse permission for each user's home folder. Consult the attached sample project for one way of achieving this.

A user can be given restricted access, so that it is only accessible from certain IP addresses / hostnames (whitelist). Alternately, access can be allowed from everywhere except for a few IP addresses / hostnames that are explicitly denied (blacklist). This behavior can be set through the "RestrictHostsBehavior" property, as follows:

UserConfig.RestrictHostsBehavior = RoboFTPServer.RestrictBehaviors.RestrictExcept; // whitelist
    or
UserConfig.RestrictHostsBehavior = RoboFTPServer.RestrictBehaviors.RestrictOnly;   // blacklist
    or
UserConfig.RestrictHostsBehavior = RoboFTPServer.RestrictBehaviors.RestrictNone;   // no restriction

The associated whitelisted / blacklisted addresses can be specified through the "RestrictedHosts" property, which contains an "Add" method:

myUserConfig.RestrictedHosts.Add("192.168.0.101");

Once a user has been successfully created, it must be added to the set of all users in the RSServerConfig objects. This can be achieved as follows:

CRSFTPServerConfig.Users.Add(ftpUser);
CRSSFTPServerConfig.Users.Add(sftpUser);

Finally, we will need to commit these changes to the running RoboFTPServer instance:

CRSFTPServerConfig.SaveConfig();
CRSSFTPServerConfig.SaveConfig();

Article last updated: 2021-01-22

Tags: Server COM C# automation