如何在Microsoft Azure App Service控制台压缩文件及安装压缩工具?
Hey there! I totally get the frustration of dealing with 3GB+ files via FTP—super slow. Let's fix this compression issue in Kudu step by step.
First, Why Your Previous Commands Failed
compressis a Linux-only command, so it won't work in Windows-based Kudu CMD.Compress-Archiveis a PowerShell cmdlet—you were probably running it in the CMD tab instead of PowerShell.zipisn't included by default in Windows CMD environments.
Option 1: Use Built-in PowerShell Compression (Easiest)
Kudu has a PowerShell tab—switch to it, and you can use the native Compress-Archive cmdlet without installing anything:
- Open your Azure App Service Kudu console (via
https://<your-app-name>.scm.azurewebsites.net). - Click the PowerShell tab at the top (instead of CMD).
- Run this command, adjusting the paths to match your files:
# Compress all files in your target folder into a single zip Compress-Archive -Path "D:\home\site\wwwroot\your-large-files-folder\*" -DestinationPath "D:\home\site\wwwroot\large-archive.zip"D:\homeis the persistent storage path for your App Service, so your compressed file will stay there until you delete it.
Option 2: Use 7-Zip for Higher Compression (If You Need It)
If you want better compression ratios (smaller file size for faster downloads), you can temporarily install 7-Zip in the Kudu environment (it won't survive an app restart, but that's fine for one-off tasks):
- Stay in the PowerShell tab, and run these commands to set up 7-Zip:
# Download the 7-Zip portable tools package Invoke-WebRequest -Uri "https://www.7-zip.org/a/7z2301-extra.7z" -OutFile "D:\home\7z-tools.7z" # Extract the package to a local folder Expand-Archive -Path "D:\home\7z-tools.7z" -DestinationPath "D:\home\7z" # Compress your files with 7-Zip (use .7z for better compression, or .zip) D:\home\7z\7z.exe a "D:\home\site\wwwroot\large-archive.7z" "D:\home\site\wwwroot\your-large-files-folder\*" - Once done, you can delete the 7-Zip files if you want to free up space.
Downloading the Compressed File to Your New Server
Once the archive is ready, use wget from your new server to pull it directly (faster than FTP):
wget https://<your-app-name>.scm.azurewebsites.net/api/vfs/site/wwwroot/large-archive.zip --user <your-deployment-username> --password <your-deployment-password>
You can find your deployment credentials in the Azure Portal under your App Service > Deployment Center > FTP Credentials.
内容的提问来源于stack exchange,提问作者Arvind K.

