You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Logic App同步FTP文件至Azure存储:检查Blob/容器并按需创建

Answer: Yes, You Can Automate Creation of Azure Storage Containers/Blob Paths in Logic Apps

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:
    split(triggerBody()?['FilePath'], '/')
    
    For example, if the file path is 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:
    replace(outputs('Compose')[0], '-', '/')
    
    This turns 01-22-2018 into 01/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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:23:30