使用 FTP/S 將您的應用程式部署至 Azure App ServiceDeploy your app to Azure App Service using FTP/S

這篇文章說明如何使用 FTP 或 FTPS 將您的 Web 應用程式、行動裝置應用程式後端或 API 應用程式部署到 Azure App Service (英文)This 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

  1. 在 [ Azure 入口網站中,搜尋並選取 [應用程式服務]。In the Azure portal, search for and select App Services.

    搜尋 [應用程式服務]。

  2. 選取您想要部署的 web 應用程式。Select the web app you want to deploy.

    選取您的應用程式。

  3. 選取 [部署中心] [ > FTP > 儀表板]。Select Deployment Center > FTP > Dashboard.

    開啟 FTP 儀表板

取得 FTP 連線資訊Get FTP connection information

在 FTP 儀表板中,選取 [複製] 以複製 FTPS 端點和應用程式認證。In the FTP dashboard, select 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 登入到訂用帳戶中的所有 App Service 應用程式。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:

<app-name>\<user-name>

由於使用者層級認證會連結至使用者,而不是特定資源,因此使用者名稱必須採用此格式,才能將登入動作導向至正確的應用程式端點。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 目錄 (或 WebJobs 的 /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 和編輯器自動化)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

為了加強安全性,您應該只允許透過 TLS/SSL 的 FTP。For enhanced security, you should allow FTP over TLS/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 將檔案上傳至 Web 應用程式 (PowerShell)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/wwwrootAll the officially supported deployment methods make changes to the files in the /home/site/wwwroot folder of your app. 這些檔案是用來執行您的應用程式。These files are used to run your app. 因此,部署可能會因為鎖定的檔案而失敗。Therefore, the deployment can fail because of locked files. 應用程式在部署期間可能也會無法預期的行為,因為並非所有檔案都同時更新。The app may also behave unpredictably during deployment, because not all the files updated at the same time. 對於客戶面向的應用程式,這是不必要的。This is undesirable for a customer-facing app. 有幾種不同的方式可以避免這些問題: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.

若要判斷部署或執行階段問題,請參閱部署與執行階段問題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 App Service 中的 FTP?How can I connect to FTP in Azure App Service via passive mode?

Azure App Service 支援透過主動與被動模式進行連線。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 部署至 Azure For 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