Azure Logic App同步FTP文件至Azure存储:检查Blob/容器并按需创建
Absolutely! This is totally achievable with Azure Logic Apps, and I’ll walk you through how to set this up to match your FTP-to-Azure Storage sync requirement—including preserving that date-based folder structure and auto-creating missing containers or virtual blob paths.
Key Concepts to Clarify First
Before diving into steps, let’s clarify the two possible hierarchy models you might use in Azure Storage:
- Date as a Container: Each FTP date folder (like
01-22-2018) becomes a dedicated storage container. - Date as a Virtual Blob Path: All files go into a single root container, with the date folder structure represented as blob prefixes (e.g.,
ftp-sync/01/22/2018/file.txt—Azure automatically handles these "virtual folders" without needing to create them upfront).
I’ll cover both scenarios below.
Step-by-Step Implementation
1. Start with the FTP Trigger
First, set up the trigger to detect new files in your FTP server:
- Add the FTP - When a file is added or modified trigger.
- Configure your FTP server connection, and set the folder path to monitor (e.g.,
/to watch all folders). - Enable the Include file path option—this is critical, as it gives you the full path of the file including its date folder.
2. Parse the FTP File Path
Use a Compose action to split the file path into its components (date folder and filename):
- Input the expression:
For example, if the file path issplit(triggerBody()?['FilePath'], '/')01-22-2018/sales-report.pdf, this will output an array like["01-22-2018", "sales-report.pdf"].
3. Handle Date Format (Optional)
If you want to convert the FTP’s MM-DD-YYYY format to a slash-separated path for virtual blob folders, add another Compose action:
- Input the expression:
This turnsreplace(outputs('Compose')[0], '-', '/')01-22-2018into01/22/2018.
Scenario 1: Date Folder = Azure Storage Container
If you want each date folder to be its own container:
a. Check if the Container Exists
Add the Azure Blob Storage - Get blob container action:
- Set the Container name to
toLower(outputs('Compose')[0])(Azure container names require lowercase letters, numbers, and hyphens only—no uppercase or special characters).
b. Auto-Create the Container if Missing
Instead of using a condition, use Logic Apps’ error handling for a cleaner flow:
- Wrap the "Get blob container" action in a Scope (name it "Check for Existing Container").
- Click the scope’s ellipsis > Configure run after, and check Failed (this means we’ll run the next action only if the container doesn’t exist).
- Add the Azure Blob Storage - Create blob container action outside the scope, using the same lowercase container name:
toLower(outputs('Compose')[0]).
c. Upload the File to the Container
Add the Azure Blob Storage - Create blob action:
- Select the container you just verified/created.
- Set Blob name to
outputs('Compose')[1](the filename from the parsed path). - Set Blob content to the file content from the FTP trigger (use
triggerBody()?['Content']).
Scenario 2: Date Folder = Virtual Blob Path (Single Root Container)
This is the simpler approach, as Azure doesn’t require you to pre-create virtual folders—they’re automatically generated when you upload a blob with a slash-separated path.
a. Upload the File with the Virtual Path
Add the Azure Blob Storage - Create blob action:
Select your root container (e.g.,
ftp-sync—create this manually first or use the auto-create method above if needed).Set Blob name to the expression:
concat(outputs('Compose_Converted_Date'), '/', outputs('Compose')[1])This creates a path like
01/22/2018/sales-report.pdf, which will appear as a folder structure in Azure Storage Explorer.Set Blob content to the FTP file content, same as scenario 1.
Important Notes
- Container Naming Rules: Always convert FTP folder names to lowercase, ensure they’re 3-63 characters long, and only use letters, numbers, and hyphens (hyphens can’t start or end the name).
- Performance Considerations: Using virtual blob paths is more efficient for most use cases—Azure storage accounts allow up to 500,000 containers, but managing hundreds of containers can get cumbersome compared to a single container with organized prefixes.
- Error Handling: Add retry policies to your FTP and Blob Storage actions to handle transient network issues.
内容的提问来源于stack exchange,提问作者andrewbuikema

