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

求助:如何通过Function App将SFTP中的文件迁移至Azure Blob?

Migrate SFTP Files to Azure Blob with Azure Function App

Hey there! Since you’ve already got this workflow working in Logic Apps, shifting it to Azure Function App is totally straightforward. Let’s walk through the steps to get your sample.xml migration running smoothly with the external file trigger you’ve configured.

1. Set Up Required Dependencies

First, make sure your Function App has the necessary packages to interact with SFTP and Azure Blob Storage:

  • For C# Functions: Install Renci.SshNet (for SFTP operations) and Azure.Storage.Blobs (for Blob interactions) via NuGet.
  • For Python Functions: Install paramiko (SFTP) and azure-storage-blob (Blob) using pip.

2. Core Function Code (C# Example)

Here’s a complete example using the external file trigger. This code will trigger when sample.xml is detected in your specified SFTP path, then copy the file directly to Azure Blob Storage:

using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public static class SftpToBlobMigration
{
    [FunctionName("SftpToBlobTransfer")]
    public static void Run(
        // External File Trigger pointing to your SFTP sample.xml path
        [ExternalFileTrigger("sftp://your-sftp-server:22/your-sftp-folder/sample.xml", 
            Connection = "SftpConnectionString")] Stream sftpFileStream,
        
        // Blob Output binding to your target container
        [Blob("your-blob-container/sample.xml", FileAccess.Write, 
            Connection = "AzureWebJobsStorage")] Stream blobOutputStream,
        
        ILogger log)
    {
        log.LogInformation($"Starting transfer of sample.xml from SFTP to Blob Storage");
        
        // Copy the SFTP file stream directly to the Blob output stream
        sftpFileStream.CopyTo(blobOutputStream);
        
        log.LogInformation($"Successfully transferred sample.xml to Azure Blob Storage!");
    }
}

3. Key Configuration Steps

  • SFTP Connection String: Add a new app setting named SftpConnectionString in your Function App’s Configuration. Format:

    Host=your-sftp-host;Port=22;Username=your-sftp-username;Password=your-sftp-password
    

    For key-based authentication, replace the password with PrivateKey=path-to-your-private-key (ensure the key is in OpenSSH format).

  • Blob Storage Connection: The AzureWebJobsStorage app setting should already point to your Blob Storage account’s connection string (make sure it has write permissions to your target container).

  • Trigger Path Validation: Double-check the SFTP path in the trigger annotation matches exactly where sample.xml is stored—typos here will prevent the trigger from firing.

4. Testing & Troubleshooting

  • Test the Trigger: Upload sample.xml to your SFTP path, then check your Function App’s Logs (under Monitor > Logs in the Azure Portal) to confirm the function ran successfully.
  • Network Issues: Ensure your SFTP server allows inbound connections from your Function App’s outbound IP addresses (find these in your Function App’s Networking settings).
  • Blob Permissions: Verify your target Blob container exists and the connection string has Storage Blob Data Contributor or equivalent permissions.

内容的提问来源于stack exchange,提问作者sreeprasad k s

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:26:03