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

使用Azure函数触发器读取SFTP位置所有文本文件的技术问询

How to Trigger Azure Function on Any Text File in SFTP Outbox

Hey there! Let's tweak your Azure Function so it automatically processes any text file dropped into your SFTP Outbox folder, instead of being limited to a specific filename. Here's the step-by-step fix:

1. Update the ExternalFileTrigger Binding Configuration

Your current binding has a fixed output filename and triggers on all files in Outbox (not just text files). Modify it to target only text files and use dynamic naming for outputs:

{
  "bindings": [
    {
      "type": "apiHubFileTrigger",
      "name": "input",
      "direction": "in",
      "path": "Outbox/*.txt", // Triggers on any .txt file in the Outbox folder
      "connection": "sftp1_SFTP"
    },
    {
      "type": "apiHubFile",
      "name": "output",
      "direction": "out",
      "path": "Inbox/{filename}", // Reuses the incoming file's name for the output
      "connection": "googledrive_GOOGLEDRIVE"
    }
  ],
  "disabled": false
}

Key Changes Breakdown:

  • path: "Outbox/*.txt": The *.txt wildcard ensures only text files trigger the function, skipping non-text files in the folder.
  • path: "Inbox/{filename}": The {filename} binding expression automatically captures the name of the triggering file, so your output in Google Drive will match the original SFTP file's name (instead of always being test.txt).

2. Adjust the Function Code

Your current code logs the file content instead of the filename, which isn't ideal for debugging. Update it to track the actual file being processed while keeping your content pass-through logic:

using System;

public static void Run(string input, out string output, string filename, TraceWriter log) {
    // Log the processed filename instead of raw content
    log.Info($"Successfully processed file: {filename}");
    // Pass the input file's content directly to the output
    output = input;
}

Key Changes Breakdown:

  • Added string filename parameter: This gets automatically populated by the binding using the {filename} expression from your config, so you can log the exact file that triggered the function.
  • Updated log message: Now it shows the filename instead of file content, making debugging and monitoring much easier.

3. Test the Behavior

Once you deploy these updates:

  • Drop any .txt file into your SFTP Outbox folder
  • The function will trigger automatically, copy the file content to Google Drive's Inbox folder with the same original filename
  • Check the function logs to confirm the correct file was processed

If you need to support additional text-based extensions (like .csv), just adjust the trigger path to Outbox/*.{txt,csv}. If you want to process all files regardless of type, use Outbox/* instead.

内容的提问来源于stack exchange,提问作者rahul

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 06:56:56