The FTP protocol is one of the oldest protocols (it is more than 40 years old), but it is still widely used where a simple file transfer protocol is required. It is possible to install an FTP server on any version of Microsoft operation system. Last deep modernization of the ftp service was made in Windows 7 / Server 2008 R2 (actually the service code has almost been written from scratch). The security of the service has significantly improved and a number of new features have appeared. In particular, FTP server on Windows allows you to configure FTP user isolation. It allows to restrict access of many users to their own folders on a single FTP server.
Due to the isolation, users can work only with their folders and can’t go up in the FTP directory tree (the user’s top ftp level directory is displayed as the root of the FTP server). Thus, the access to the data of other users on the FTP server can be prevented. FTP user isolation is widely used by ISP/hosting providers when it is necessary to provide individual access to a single file storage for different users.
Like in previous Windows versions, the FTP service in Windows Server 2016 / 2012 R2 (do not confuse it with sFTP and TFTP) is based and deeply integrated into the IIS service and has a single administrative management interface.
In this article we’ll show how to install an IIS-based FTP server on Windows Server 2016/2012 R2 and configure the FTP user isolation (this manual also applies to Windows 10 and 8.1).
How to Install the FTP Server Role on Windows Server 2016/ 2012 R2?
You can install the FTP service using the Server Manager console by checking the option FTP Service and FTP Extensibility in the section Web Server (IIS) -> FTP Server.
To install the FTP server management console, run the following command:
Install-WindowsFeature -Name "Web-Mgmt-Console"
Creating an FTP Site, Managing FTP User Permissions
Start the Server Manager and open the IIS management console (Internet Information Service Manager).
Create a new FTP site (Sites -> Add FTP Site).
The name of the FTP site: MyTestSite
The root directory of the FTP site: C:\inetpub\ftproot
To protect the FTP data transmitted over the network, it is possible to configure SSL for FTP (in this case, all the data and passwords/accounts sent by ftp users during session will be encrypted), but in our demonstration this is not necessary. All other settings are left default.
# Set the FTP site name
$FTPSiteName = 'CORP_FTP'
$FTPRoot = 'D:\www\FTPRoot'
$FTPPort = 21
New-WebFtpSite -Name $FTPSiteName -PhysicalPath $FTPRoot -Port $FTPPort
Select a new FTP site and disable the Anonymous Authentication in the FTP Authentication section. Basic Authentication must be enabled.
The FTP service on Windows Server 2016/2012 R2 can use two account types: domain or local. Depending on the account type, there are some differences in the structure of FTP directories and user isolation settings. To make it easier to describe, we will use local Windows accounts.
Create some FTP users, suppose, these are ftp_user1, ftp_user2 and ftp_user3. Also create a group ftp_users which includes these users. You can create local users in the Local Users and Groups section of the Computer Management console.
You can also create local users and groups from the command prompt (or using PowerShell). Create a local group:
net localgroup ftp_users /add
Create the two other users in the same way.
Assign the Read&Write permissions on the directory C:\inetpub\ftproot for the ftp_users group.
Create a directory with the name LocalUser (the name must be the same, it’s important!!!) in the folder C:\inetpub\ftproot. Then make three directories under with the names ftp_user1, ftp_user2, ftp_user3 in the folder C:\inetpub\ftproot\LocalUser.
|Account Type||Syntax of Home Directory Naming|
|Local Windows account||%FtpRoot%\LocalUser\%UserName%|
|Domain Windows account||%FtpRoot%\%UserDomain%\%UserName%|
|Special IIS Manager or ASP.NET accounts||%FtpRoot%\LocalUser\%UserName%|
Return to the IIS console and create a new rule (Add AllowRules) in FTP Authorization Rules section of the site. Specify that ftp_users group must have the read and write permisions.
How to Configure FTP User Isolation on Windows Server 2016/2012 R2?
Let’s move to configuring FTP user isolation. The isolation of FTP users is configured on the FTP site level, not the entire server. FTP user isolation allows you to organize your ftp-home folder for each user.
Open FTP User Isolation in the settings of the FTP site.
This section contains several settings. The first two of them don’t suggest user isolation:
- FTP root directory (an FTP session of a user starts in the root directory of the FTP site);
- User name directory (the user starts with physical/virtual directory with the username. If the directory is missing, a session starts in the root FTP directory of the site).
The next three options are different modes of user isolation:
- User name directory (disable global virtual directories) suggests that the ftp session of a user is isolated in a physical/virtual directory that has the same name as the ftp user. Users see only their own directory (it is their root ftp-directory) and cannot go beyond it (to the upper directory of the FTP tree). Any global virtual directories are ignored;
- User name physical directory (enable global virtual directories) suggests that the ftp session of a user is isolated in a physical directory that has the same name as the name of the ftp user account. A user cannot go above its directory. However, all created global virtual directories are available to the user;
- FTP home directory configured in Active Directory – an FTP user is isolated within his home directory specified in the settings of his Active Directory account (FTPRoot and FTPDir properties).
Select the required isolation mode (I use the second option to isolate ftp users).
Configuring Windows Firewall Rules to Access the FTP Server
When you install the FTP server role, all necessary rules that are needed for users to access FTP are automatically activated in the Windows Firewall settings.
For FTP to work correctly in passive FTP mode, users need to connect to the RPC port range (1025-65535). In order not to open all these ports on an external firewall, you can limit the range of dynamic TCP ports used for FTP data transmission.
- Open the FTP Firewall Support section in FTP site settings and in the Data Channel Port Range field specify the port range that you want to use for FTP connections. For example – 50000-50100;
- Save the changes and restart IIS (
- Open the Windows Control Panel and go to the Control Panel\System and Security\Windows Firewall\Allowed apps;
- Make sure that the list of applications that are allowed access through the firewall contains permissions for the FTP Server role.
Then check that the following rules are enabled in the settings of Windows Firewall with Advanced Security:
- FTP Server (FTP Traffic-In) – TCP protocol, port 21;
- FTP Server Passive (FTP Passive Traffic-In) – local port address 1024-65535 (50000-50100 in our case);
- FTP Server Secure (FTP SSL Traffic-In) –port 990 (when using FTP with SSL);
- FTP Server (FTP Traffic-Out) – port 20;
- FTP Server Secure (FTP SSL Traffic-Out) –port 989 (when using FTP with SSL).
Accordingly, these ports need to be opened on your router (gateway, firewall) so that external FTP users can connect to your site.
Testing an FTP Server Connection from Windows
You can check the availability of ports on an FTP server using the Test-NetConnection cmdlet:
Test-NetConnection -ComputerName yourftpservername -Port 21
Or using the ftp command:
Try to connect to your FTP site with any FTP client or directly from File Explorer (specify ftp://yourservername/ in the address bar).
Enter the user name and password.
And now you have access to the home directory with the user’s files (which is the root of the FTP site for the user). As we can see, the user session is isolated and the user sees only his files on the ftp server.
You can use FTP logs to view information about user access to the FTP server. The log files are stored by default in the c:\inetpub\logs\logfiles folder in the u_exYYMMDD.log files.
To view the active user connections to your FTP server, you can use the values of the IIS performance counters through PowerShell or the “Current FTP Sessions” section in the IIS console. In this console, you can view the names and the IP address of the FTP user’s and disconnect the ftp-session if necessary.
So, we have looked at how to configure an FTP site with the user isolation based on Windows Server 2016 / 2012 R2. In the isolation mode the users are authenticated on FTP using their local or domain credentials to access their root directory corresponding to the username.