Deploying ASP .NET app to FTP with Azure DevOps CI/CD pipeline

Fast-track your deployments! Dive straight into the essentials of deploying your ASP .NET application via FTP. With the Azure DevOps CI/CD pipeline and our comprehensive YAML file guidance, you'll be set for streamlined deployments in no time.

Set Up ASP .NET Pipeline in 5 Simple Steps

To ensure a successful deployment of your files to the desired FTP location, your pipeline should:

  1. Activate immediately after a commit to a specified branch (e.g., master).
  2. Utilize the latest Windows machine for building the solution in 'Release' mode.
  3. Restore NuGet packages.
  4. Export the web app to a designated file system directory.
  5. Transfer the files to the FTP server with the FtpUpload task. For a deeper understanding, consider checking Microsoft's official documentation on the FTPUpload task.

Complete Azure pipeline YAML with FtpUpload task

This YAML file outlines the Azure DevOps pipeline for an ASP.NET application, specifying the build and deployment process.

Let me break down its main components for clarity:

  1. Triggers and Environment:

    • The pipeline is triggered whenever there's a commit to the master branch.
    • It uses the latest Windows virtual machine image.
  2. Variables:

    • Defines the solution files, build platform, and configuration.
  3. Steps:

    a. NuGet Setup:

    • First, the pipeline ensures that the NuGet tool is installed.
    • Then, it restores any missing packages using the NuGet command.

    b. Building the Solution:

    • It uses the Visual Studio Build (VSBuild) task to build the specified solution.
    • The build configuration is set to Release, and it publishes the web app to a file system directory.

    c. Testing:

    • After building, the pipeline runs tests using the VSTest task.

    d. FTP Upload:

    • The last task, FtpUpload, uploads the built website to an FTP server.
    • It uses the specified credentials to connect to the server.
    • The files from the artifact staging directory are uploaded to the /wwwroot directory of the server.
    • This task has several configuration options like preserving paths, trusting SSL, etc.
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:

- master

  vmImage: 'windows-latest'

  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
    restoreSolution: '$(solution)'

- task: VSBuild@1
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl=$(build.artifactstagingdirectory)\website'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: FtpUpload@2
    credentialsOption: 'inputs'
    serverUrl: ''
    username: 'ftp-user-name'
    password: 'P@ssword'
    rootDirectory: '$(build.artifactStagingDirectory)/website'
    filePatterns: '**'
    remoteDirectory: '/wwwroot' # '/wwwroot/$(Build.BuildId)/'
    clean: false
    cleanContents: false
    preservePaths: true
    trustSSL: false

Please ensure to modify sensitive details like the username and password before deploying.

Also, remember to adjust the serverUrl from its placeholder value ( to your actual FTP server's address.

FTP Upload Limitations

FTP (File Transfer Protocol) is a standard network protocol used to transfer files from one host to another over a TCP-based network, such as the Internet.

While FTP can be a convenient way to deploy ASP.NET applications, especially in environments where more sophisticated deployment mechanisms are not available, it comes with several limitations that you should be aware of:

  • Security Concerns: FTP does not inherently encrypt its traffic. Any data transferred via FTP, including potentially sensitive information like usernames and passwords, can be intercepted and read by others. Using FTP over SSL/TLS (FTPS) or SSH File Transfer Protocol (SFTP) can mitigate this risk.
  • Reliability Issues: FTP does not guarantee file integrity or successful transfer completion. Network issues or server problems can result in partial or failed uploads without proper error handling and retry mechanisms in place.
  • Limited Error Reporting: Standard FTP clients and libraries may provide limited error reporting capabilities, making it difficult to diagnose and troubleshoot deployment issues.
  • Scalability and Performance: FTP may not be the most efficient protocol for deploying large applications or handling frequent updates, especially in high-latency networks. The lack of compression and the overhead of establishing connections for each file can lead to slower deployment times.
  • Access Control Limitations: Managing fine-grained access controls and permissions can be challenging with FTP, potentially leading to security vulnerabilities if not handled correctly.

For a more secure, reliable, and efficient deployment of ASP.NET applications, consider using Web Deploy (MSDeploy) or Docker.

Web Deploy integrates closely with IIS, improves error handling, and supports incremental updates.

Get the Source Code and Stay Updated

For an in-depth exploration and hands-on experience, download the source code for this article directly from GitHub repository

And for the latest updates, tips, and more developer insights, don't forget to follow us on Social Media!

Your support keeps us motivated to produce more content like this.

Happy coding!

↑ Top ↑