Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to install and configure an FTP server in Windows using PowerShell

If you want to know how to install and configure an FTP server on Windows using PowerShell join us throughout this brief tutorial where we will do it in simple steps.

This tutorial complements the one we already did through the graphical interface and which we titled How to install and configure an FTP server on Windows (IIS){target="_blank" rel="noopener"}.

NOTE: A hash (#) has been added in front of all the lines for security reasons, since if one of these lines is copied by mistake it will not be executed (the hash is used to comment out code, so it becomes non-executable). To run it, the "#" character must be removed from all lines.

How to install and configure an FTP server on Windows using PowerShell?

Prerequisites or pre-configuration.

To successfully complete this tutorial and be able to install and configure an FTP server on Windows using PowerShell the following will be needed:

  • On the one hand, being registered on the Plenit Platform with an organization and being registered in it after doing Log-in{target="_blank" rel="noopener"}.

  • On the other hand, having subscribed to a Servers subscription{target="_blank" rel="noopener"}

  • Having a working Windows server within the subscription.

Step 1. Install and configure an FTP server on Windows using PowerShell

The first thing we will do will be install the FTP server functionality, for which you will need to launch the PowerShell console, or PowerShell ISE. As I have been saying lately, the most desirable thing would be to use ISE (so to speak, Microsoft's IDE), since it allows us to test, see where it fails, etc.

Once in the PowerShell console (or ISE), we must run the "Install-WindowsFeature" commands (1).

# Install-WindowsFeature Web-FTP-Server -IncludeAllSubFeature

# Install-WindowsFeature Web-Server -IncludeAllSubFeature -IncludeManagementTools

# Import-Module WebAdministration

Where:

  • The command "Install-WindowsFeature" installs the functionality of Windows that we pass as a parameter.

  • The modifier "-IncludeAllSubFeature" installs all options that the Windows feature has.

  • The modifier "-IncludeManagementTools" installs the administrative tools for that functionality.

Step 1. We deploy the FTP service using PowerShell

Once this is done, we continue the installation by importing the FTP administration module using the command "Import-Module" (2).

Step 1. We import the FTP administration module using PowerShell

Next, the new FTP site is configured to provide service.

This will have a series of characteristics that must be configured, and a command like the following can be run directly:

*# New-WebFtpSite -Name \ -Port -PhysicalPath *

Where:

  • The command "New-WebFtpSite" deploys the new FTP site. FTP.

  • "-Name " describes the name that we will give to the FTP site.

  • "-Port " is a number that indicates which port the FTP listens on.

  • "-PhysicalPath " is the server path where the FTP data is located.

This way, it could look like this:

# New-WebFtpSite -Name 'FTP Site Nacho' -Port '21' -PhysicalPath 'C:\datos\ftproot'

We could replace it directly there and have the configuration done, but this is a bit of a bodge, so variables are usually used to improve use on future occasions.

To keep everything more organized, we will create some variables, as we mentioned, which will be the following:

  • "-Name " describes the name that we will give the site of FTP, with the variable "$Name".

  • "-Port " is a number that indicates which port the FTP listens on, with the variable "$Port".

  • "-PhysicalPath " is the server path where the data of the FTP are located, with the variable "$Root".

Taking this into account, everything is configured and the following commands are executed the following commands (3):

# $Name = 'FTP Site Nacho'

# $Root = 'C:\datos\ftproot'

# $Port = 21

# New-WebFtpSite -Name $Name -Port $Port -PhysicalPath $Root

Step 1. We configure the FTP site for the service

At this point, the FTP server itself has already been installed, and what remains is configure, add users, repositories, securing it, etc.

At this point, for me, the first thing would be to create a user (and its associated group) in order to test that we can make the connection and not just assume it. That way, if we later secure it by closing ports or configuring certificates, we will be sure that this part was working.

In this case, first we create a group for the users with the ability to connect to the FTP, since it is better to create a group that can be added to later.

To create the FTP group (4) we use:

# $FTPUserGroupName = «FTP Users»

# $ADSI = [ADSI]»WinNT://$env:ComputerName»

# $FTPUserGroup = $ADSI.Create(«Group», «$FTPUserGroupName»)

# $FTPUserGroup.SetInfo()

# $FTPUserGroup.Description = «Members of this group can connect to the FTP»

# $FTPUserGroup.SetInfo()

Step 1. We create the FTP group for the service

In this case, we will make use of ADSI commands for deploying the group, as always using certain variables to make the configuration easier.

The next thing would be to create the user with which the FTP connections will be made (5).

# $FTPUserName = «ftpnacho»

# $FTPPassword = 'Contrasenya123!'

# $CreateUserFTPUser = $ADSI.Create(«User», «$FTPUserName»)

# $CreateUserFTPUser.SetInfo()

# $CreateUserFTPUser.SetPassword(«$FTPPassword»)

# $CreateUserFTPUser.SetInfo()

Step 1. We create a user for FTP connections

Once this is done, it must be added to the system FTP group (6), by executing:

# $UserAccount = New-Object System.Security.Principal.NTAccount(«$FTPUserName»)

# $SID = $UserAccount.Translate([System.Security.Principal.SecurityIdentifier])

# $Group = [ADSI]»WinNT://$env:ComputerName/$FTPUserGroupName,Group»

# $User = [ADSI]»WinNT://$SID»

# $Group.Add($User.Path)

Step 1. We add the FTP user to the system FTP group

At this point you must enable basic authentication on the FTP site and then authorize the Windows group (7) that contains the FTP user so that it can have access to the FTP site and therefore make use of the service.

To do this, the following commands must be executed:

[# $FTPSitePath][ = ][«IIS:\Sites\][$FTPSiteName][«]

[# $BasicAuth][ = ]['ftpServer.security.authentication.basicAuthentication.enabled']

[[# ]Set-ItemProperty][ -Path ][$FTPSitePath][ -Name ][$BasicAuth][ -Value ][$True]

[# $Param][ = @][{]

[[# ]Filter][ = ][«/system.ftpServer/security/authorization»]

[ [# ]Value = @][{]

[ [# ]accessType = ][«Allow»]

[ [# ]roles = ][«][$FTPUserGroupName][«]

[ [# ]permissions = ][1]

[[# ]}]

[ [# ]PSPath = 'IIS:\']

[ [# ]Location = ][$FTPSiteName]

[[# ]}]

[[# ]Add-WebConfiguration][ @][param]

Step 1. We configure basic authentication for our FTP site

The next step is to change the SSL policy and file permissions (NTFS) in the folder FTP server root (8), that is, where all files uploaded by service users are stored.

To do this, we execute the following commands:

# $SSLPolicy = @(

# 'ftpServer.security.ssl.controlChannelPolicy',

# 'ftpServer.security.ssl.dataChannelPolicy'

# )

# Set-ItemProperty -Path $FTPSitePath -Name $SSLPolicy[0] -Value $false

# Set-ItemProperty -Path $FTPSitePath -Name $SSLPolicy[1] -Value $false

Step 1. We change the SSL policy and file permissions in the FTP server root folder

The next step to take is to run the following commands to configure NTFS permissions in the root folder and thus allow users who belong to the FTP group to access and work on this folder.

# $UserAccount = New-Object System.Security.Principal.NTAccount(«$FTPUserGroupName»)

# $AccessRule = [System.Security.AccessControl.FileSystemAccessRule]::new($UserAccount,

# 'ReadAndExecute',

# 'ContainerInherit,ObjectInherit',

# 'None',

# 'Allow'

# )

# $ACL = Get-Acl -Path $FTPRootDir

# $ACL.SetAccessRule($AccessRule)

# $ACL | Set-Acl -Path $FTPRootDir

Finally, for all changes to take effect the FTP instance must be restarted (9), to do this the following must be executed:

# Restart-WebItem «IIS:\Sites\$Name» -Verbose

Step 1. We restart the FTP service from the PowerShell console

With this, the FTP configuration process is complete.

Conclusions and next steps:

Throughout this tutorial we have seen how to carry out the installation and configuration of an FTP server on Windows using PowerShell within one of the Windows servers hosted in Plenit.

If what you have read so far has been interesting, you can delve further into some related services; the following tutorials may interest you:

We hope that, with this small guide, you will have no problems configuring your FTP server quickly and functionally, but if you do, do not hesitate to contact us so we can give you a hand.

Thank you for your trust.

Last updated

Was this helpful?