使用 FTP/S 将应用部署到 Azure 应用服务Deploy your app to Azure App Service using FTP/S

本文介绍了如何使用 FTP 或 FTPS 将 Web 应用、移动应用后端或 API 应用部署到 Azure App ServiceThis article shows you how to use FTP or FTPS to deploy your web app, mobile app backend, or API app to Azure App Service.

应用的 FTP/S 终结点已处于活动状态。The FTP/S endpoint for your app is already active. 启用 FTP/S 部署不需要进行任何配置。No configuration is necessary to enable FTP/S deployment.

打开 FTP 仪表板Open FTP dashboard

Azure 门户中,打开应用的资源页In the Azure portal, open your app's resource page.

若要打开 FTP 仪表板,请单击“部署中心” > “FTP” > “仪表板” 。To open the FTP dashboard, click Deployment Center > FTP > Dashboard.

打开 FTP 仪表板

获取 FTP 连接信息Get FTP connection information

在 FTP 仪表板中,单击“复制” 以复制 FTPS 终结点和应用凭据。In the FTP dashboard, click Copy to copy the FTPS endpoint and app credentials.

复制 FTP 信息

建议你使用应用凭据部署到应用,因为它对每个应用都是唯一的。It's recommended that you use App Credentials to deploy to your app because it's unique to each app. 但是,如果单击“用户凭据” ,会将可用于 FTP/S 登录的用户级凭据设置到订阅中的所有应用服务应用。However, if you click User Credentials, you can set user-level credentials that you can use for FTP/S login to all App Service apps in your subscription.


使用用户级凭据向 FTP/FTPS 终结点进行身份验证时需要使用以下格式的用户名:Authenticating to an FTP/FTPS endpoint using user-level credentials requirers a username in the following format:


由于用户级凭据链接到用户而不是特定资源,因此用户名必须采用此格式才能将登录操作定向到正确的应用终结点。Since user-level credentials are linked to the user and not a specific resource, the username must be in this format to direct the sign-in action to the right app endpoint.

将文件部署到 AzureDeploy files to Azure

  1. 从 FTP 客户端(例如 Visual StudioCyberduckWinSCP),使用收集到的连接信息连接到应用。From your FTP client (for example, Visual Studio, Cyberduck, or WinSCP), use the connection information you gathered to connect to your app.
  2. 将文件及其各自的目录结构复制到 Azure 中的 /site/wwwroot 目录(对于 Web 作业,复制到 /site/wwwroot/App_Data/Jobs/ 目录) 。Copy your files and their respective directory structure to the /site/wwwroot directory in Azure (or the /site/wwwroot/App_Data/Jobs/ directory for WebJobs).
  3. 浏览到应用的 URL,以验证该应用是否正在正常运行。Browse to your app's URL to verify the app is running properly.


基于 Git 的部署不同,FTP 部署不支持以下部署自动化:Unlike Git-based deployments, FTP deployment doesn't support the following deployment automations:

  • 还原依赖项(如 NuGet、NPM、PIP 和 Composer 自动化)dependency restores (such as NuGet, NPM, PIP, and Composer automations)
  • 编译 .NET 二进制文件compilation of .NET binaries
  • 生成 web.config(以下提供一个 Node.js 示例generation of web.config (here is a Node.js example)

在本地计算机上手动生成这些必要的文件,并将它们与应用一起部署。Generate these necessary files manually on your local machine, and then deploy them together with your app.

强制实施 FTPSEnforce FTPS

为了增强安全性,只应启用基于 SSL 的 FTP。For enhanced security, you should allow FTP over SSL only. 如果不使用 FTP 部署,也可禁用 FTP 和 FTPS。You can also disable both FTP and FTPS if you don't use FTP deployment.

Azure 门户的应用资源页中,从左侧导航中选择“配置” > “常规设置” 。In your app's resource page in Azure portal, select Configuration > General settings from the left navigation.

若要禁用未加密的 FTP,请在“FTP 状态” 中选择“仅 FTPS” 。To disable unencrypted FTP, select FTPS Only in FTP state. 若要完全禁用 FTP 和 FTPS,请选择“禁用” 。To disable both FTP and FTPS entirely, select Disabled. 完成后,单击“保存” 。When finished, click Save. 如果使用“仅 FTPS” ,则必须通过导航到 Web 应用的“TLS/SSL 设置”边栏选项卡来强制实施 TLS 1.2 或更高版本。 If using FTPS Only, you must enforce TLS 1.2 or higher by navigating to the TLS/SSL settings blade of your web app. TLS 1.0 和 1.1 不支持“仅 FTPS”。 TLS 1.0 and 1.1 are not supported with FTPS Only.

禁用 FTP/S

使用脚本自动执行Automate with scripts

若要使用 Azure CLI 进行 FTP 部署,请参阅创建 Web 应用并使用 FTP (Azure CLI) 部署文件For FTP deployment using Azure CLI, see Create a web app and deploy files with FTP (Azure CLI).

若要使用 Azure PowerShell 进行 FTP 部署,请参阅使用 FTP (PowerShell) 将文件上传到 Web 应用For FTP deployment using Azure PowerShell, see Upload files to a web app using FTP (PowerShell).

部署期间我的应用会发生什么情况?What happens to my app during deployment?

所有官方支持的部署方法都会更改应用的 /home/site/wwwroot 文件夹中的文件。All the officially supported deployment methods make changes to the files in the /home/site/wwwroot folder of your app. 这些文件与生产中运行的文件相同。These files are the same ones that are run in production. 因此,部署可能会因为文件锁定而失败。Therefore, the deployment can fail because of locked files. 生产中的应用在部署期间的行为也可能无法预测,因为不是所有文件都同时更新。The app in production may also behave unpredictably during deployment, because not all the files updated at the same time. 可通过多种不同方式避免这些问题:There are a few different ways to avoid these issues:

排查 FTP 部署问题Troubleshoot FTP deployment

如何排查 FTP 部署问题?How can I troubleshoot FTP deployment?

若要排查 FTP 部署问题,第一步是厘清部署问题和运行时应用程序问题。The first step for troubleshooting FTP deployment is isolating a deployment issue from a runtime application issue.

部署问题通常会导致无文件部署到应用,或者部署到应用的文件错误。A deployment issue typically results in no files or wrong files deployed to your app. 可以通过调查 FTP 部署情况,或者选择备用部署路径(例如源代码管理)来进行故障排除。You can troubleshoot by investigating your FTP deployment or selecting an alternate deployment path (such as source control).

出现运行时应用程序问题时,通常部署到应用的文件集是正确的,但应用行为不正确。A runtime application issue typically results in the right set of files deployed to your app but incorrect app behavior. 可以通过重点查看运行时的代码行为,并调查具体的故障路径来进行故障排除。You can troubleshoot by focusing on code behavior at runtime and investigating specific failure paths.

若要确定问题是部署问题还是运行时问题,请参阅 Deployment vs. runtime issues(部署问题和运行时问题)。To determine a deployment or runtime issue, see Deployment vs. runtime issues.

我无法通过 FTP 来发布代码。I'm not able to FTP and publish my code. 如何解决此问题?How can I resolve the issue?

检查是否输入了正确的主机名和凭据Check that you've entered the correct hostname and credentials. 另请检查计算机上的以下 FTP 端口是否未被防火墙阻止:Check also that the following FTP ports on your machine are not blocked by a firewall:

  • FTP 控制连接端口:21FTP control connection port: 21
  • FTP 数据连接端口:989、10001-10300FTP data connection port: 989, 10001-10300

如何在 Azure 应用服务中通过被动模式连接到 FTP?How can I connect to FTP in Azure App Service via passive mode?

Azure 应用服务支持通过“主动”模式和“被动”模式进行连接。Azure App Service supports connecting via both Active and Passive mode. 首选“被动”模式,因为部署计算机通常位于防火墙后面(不管是在操作系统中,还是在家庭网络或企业网络中)。Passive mode is preferred because your deployment machines are usually behind a firewall (in the operating system or as part of a home or business network). 请参阅 WinSCP 文档中的示例See an example from the WinSCP documentation.

后续步骤Next steps

有关更高级的部署方案,请参阅使用 Git 部署到 AzureFor more advanced deployment scenarios, try deploying to Azure with Git. 通过基于 Git 的 Azure 部署可实现版本控制、包还原、MSBuild 等功能。Git-based deployment to Azure enables version control, package restore, MSBuild, and more.

更多资源More resources