【问题标题】:Azure functions - Read all files from SFTP locationAzure 函数 - 从 SFTP 位置读取所有文件
【发布时间】:2018-01-02 06:37:49
【问题描述】:

我需要使用 Azure 函数触发器从 SFTP 位置(不指定文件名)读取所有可用的文本文件。 目前,当指定文件名时,我可以读取特定文件 - 如下所示: 外部文件触发器 绑定:

{
  "bindings": [
    {
      "type": "apiHubFileTrigger",
      "name": "input",
      "direction": "in",
      "path": "Outbox",
      "connection": "sftp1_SFTP"
    },
    {
      "type": "apiHubFile",
      "name": "output",
      "direction": "out",
      "path": "Inbox/test.txt",
      "connection": "googledrive_GOOGLEDRIVE"
    }
  ],
  "disabled": false
}

功能:

using System;
public static void Run(string input, out string output, TraceWriter log)
{
    log.Info("File found: "+input);
    output = input;
}

请求正文:

Outbox/test.txt

注意:无论推送到 SFTP 位置的文件名如何,Azure 函数都应读取任何文件。

【问题讨论】:

  • 你在这里没有做太多尝试,我没有看到任何 sftp 代码。查看github.com/sshnet/SSH.NET,您可以使用它连接到您的 sftp 服务器并检索文件名。
  • 嗨.. 感谢您的 cmets。我确实使用 SSH.NET 来连接 SFTP。但我希望使用输入/输出绑定来做同样的事情。我还想在读取文件后从 SFTP 位置删除文件。
  • 您的触发器未指定文件名。我错过了什么?
  • 绑定中不应包含文件名,并从指定文件夹拉取所有文本文件
  • @pmcilreavy Azure 函数在连接到 SFTP 站点时没有 SFTP 代码。您在工具中建立连接。

标签: c# .net azure sftp azure-functions


【解决方案1】:

您可以使用Binding parameters 代替硬编码文件名称:test.txt。您还可以指定文件名的模式。详情请见here

【讨论】:

    【解决方案2】:

    但是为什么要自己实例化 SFTP 客户端呢?

    只需使用预建的SFTP connector in Logic Apps,并调用函数来进一步进行自定义处理。如果您的目标是 store the file in Google Drive,您可能可以在 Logic App 中执行所有操作。

    【讨论】:

    • Azure 函数使用逻辑应用中可用的相同 SFTP 连接器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2023-01-09
    • 1970-01-01
    • 2022-06-10
    • 2022-01-23
    相关资源
    最近更新 更多