使用 SSH 和 Azure 逻辑应用监视、创建和管理 SFTP 文件Create and manage SFTP files using SSH and Azure Logic Apps

若要使用 Secure Shell (SSH) 协议自动完成用于在采用安全文件传输协议 (SFTP) 的服务器上创建和管理文件的任务,可以使用 Azure 逻辑应用和 SFTP-SSH 连接器来生成并自动完成集成工作流。To automate tasks that create and manage files on a Secure File Transfer Protocol (SFTP) server using the Secure Shell (SSH) protocol, you can create automated integration workflows by using Azure Logic Apps and the SFTP-SSH connector. SFTP 是通过任何可靠数据流提供文件访问、文件传输和文件管理的网络协议。SFTP is a network protocol that provides file access, file transfer, and file management over any reliable data stream.

下面是可以自动完成的一些示例任务:Here are some example tasks you can automate:

  • 添加或更改文件时进行监视。Monitor when files are added or changed.
  • 获取、创建、复制、重命名、更新、列出和删除文件。Get, create, copy, rename, update, list, and delete files.
  • 创建文件夹。Create folders.
  • 获取文件内容和元数据。Get file content and metadata.
  • 将存档提取到文件夹。Extract archives to folders.

在工作流中,可以使用触发器来监视 SFTP 服务器上的事件,并使输出可为其他操作所用。In your workflow, you can use a trigger that monitors events on your SFTP server and makes output available to other actions. 可以使用操作针对 SFTP 服务器执行各种任务。You can then use actions to perform various tasks on your SFTP server. 还可以让其他操作使用来自 SFTP-SSH 操作的输出。You can also include other actions that use the output from SFTP-SSH actions. 例如,如果你定期从 SFTP 服务器检索文件,则可以使用 Office 365 Outlook 连接器或 Outlook.com 连接器发送有关这些文件及其内容的电子邮件警报。For example, if you regularly retrieve files from your SFTP server, you can send email alerts about those files and their content using the Office 365 Outlook connector or Outlook.com connector. 如果你不熟悉逻辑应用,请查看什么是 Azure 逻辑应用?If you're new to logic apps, review What is Azure Logic Apps?

有关 SFTP-SSH 连接器和 SFTP 连接器之间的差异,请参阅本主题后面的比较 SFTP-SSH 与 SFTP 部分。For differences between the SFTP-SSH connector and the SFTP connector, review the Compare SFTP-SSH versus SFTP section later in this topic.

限制Limits

  • SFTP-SSH 连接器目前不支持以下 SFTP 服务器:The SFTP-SSH connector currently doesn't support these SFTP servers:

    • IBM DataPowerIBM DataPower
    • MessageWayMessageWay
    • OpenText Secure MFTOpenText Secure MFT
    • OpenText GXSOpenText GXS
  • 支持分块的 SFTP-SSH 操作最多可以处理 1 GB 的文件,而不支持分块的 SFTP-SSH 操作最多可以处理 50 MB 的文件。SFTP-SSH actions that support chunking can handle files up to 1 GB, while SFTP-SSH actions that don't support chunking can handle files up to 50 MB. 默认分块大小为 15 MB。The default chunk size is 15 MB. 但是,此大小可动态变化,最小为 5 MB,并可逐渐增加,最大为 50 MB。However, this size can dynamically change, starting from 5 MB and gradually increasing to the 50-MB maximum. 大小的动态调整视诸如网络延迟、服务器响应时间等因素而定。Dynamic sizing is based on factors such as network latency, server response time, and so on.

    当改用指定固定区块大小时,可以重写此自适应行为。You can override this adaptive behavior when you specify a constant chunk size to use instead. 此大小的范围为 5 MB 到 50 MB。This size can range from 5 MB to 50 MB. 例如,假设你有一个 45 MB 的文件,以及一个可以支持该文件大小且没有延迟的网络。For example, suppose you have a 45-MB file and a network that can that support that file size without latency. 自适应分块会导致多次调用,而不是一次调用。Adaptive chunking results in several calls, rather that one call. 若要减少调用次数,可以尝试设置 50 MB 的区块大小。To reduce the number of calls, you can try setting a 50-MB chunk size. 在不同情况下,如果逻辑应用超时(例如,当使用 15 MB 的块时),可以尝试将该大小减小到 5 MB。In different scenario, if your logic app is timing out, for example, when using 15-MB chunks, you can try reducing the size to 5 MB.

    分块大小与连接相关联。Chunk size is associated with a connection. 这个属性意味着你可以为支持分块的操作和不支持分块的操作使用同一个连接。This attribute means you can use the same connection for both actions that support chunking and actions that don't support chunking. 在这种情况下,不支持分块的操作的区块大小范围为 5 MB 到 50 MB。In this case, the chunk size for actions that don't support chunking ranges from 5 MB to 50 MB. 下表显示了哪些 SFTP-SSH 操作支持分块:This table shows which SFTP-SSH actions support chunking:

    操作Action 分块支持Chunking support 重写区块大小支持Override chunk size support
    复制文件Copy file No 不适用Not applicable
    创建文件Create file Yes Yes
    创建文件夹Create folder 不适用Not applicable 不适用Not applicable
    删除文件Delete file 不适用Not applicable 不适用Not applicable
    将存档提取到文件夹Extract archive to folder 不适用Not applicable 不适用Not applicable
    获取文件内容Get file content Yes Yes
    使用路径获取文件内容Get file content using path Yes Yes
    获取文件元数据Get file metadata 不适用Not applicable 不适用Not applicable
    使用路径获取文件元数据Get file metadata using path 不适用Not applicable 不适用Not applicable
    列出文件夹中的文件List files in folder 不适用Not applicable 不适用Not applicable
    重命名文件Rename file 不适用Not applicable 不适用Not applicable
    更新文件Update file No 不适用Not applicable
  • SFTP-SSH 触发器不支持消息分块。SFTP-SSH triggers don't support message chunking. 请求文件内容时,触发器仅选择 15 MB 或更小的文件。When requesting file content, triggers select only files that are 15 MB or smaller. 若要获取大于 15 MB 的文件,请改为遵循以下模式:To get files larger than 15 MB, follow this pattern instead:

    1. 使用只返回文件属性的 SFTP-SSH 触发器。Use an SFTP-SSH trigger that returns only file properties. 这些触发器具有包含说明的名(仅限属性)。These triggers have names that include the description, (properties only).

    2. 在使用触发器后,采取 SFTP-SSH Get file content(获取文件内容)操作。Follow the trigger with the SFTP-SSH Get file content action. 这一操作将读取完整的文件并默认使用消息区块。This action reads the complete file and implicitly uses message chunking.

SFTP-SSH 与 SFTP 的比较Compare SFTP-SSH versus SFTP

以下列表描述了不同于 SFTP 连接器的密钥 SFTP SSH 功能:The following list describes key SFTP-SSH capabilities that differ from the SFTP connector:

  • 使用 SSH.NET 库,该库是支持 .NET 的开源安全外壳 (SSH) 库。Uses the SSH.NET library, which is an open-source Secure Shell (SSH) library that supports .NET.

  • 提供“创建文件夹”操作,用于在 SFTP 服务器上的指定路径中创建文件夹。Provides the Create folder action, which creates a folder at the specified path on the SFTP server.

  • 提供“重命名文件”操作,用于在 SFTP 服务器上重命名文件。Provides the Rename file action, which renames a file on the SFTP server.

  • 缓存至 SFTP 服务器的链接,缓存时间可长达 1 小时。Caches the connection to SFTP server for up to 1 hour. 此功能可提高性能并减少连接器尝试连接到服务器的频率。This capability improves performance and reduces how often the connector tries connecting to the server. 若要设置此缓存行为的持续时间,请在 SFTP 服务器上编辑 SSH 配置中的 ClientAliveInterval 属性To set the duration for this caching behavior, edit the ClientAliveInterval property in the SSH configuration on your SFTP server.

必备条件Prerequisites

  • Azure 订阅。An Azure subscription. 如果没有 Azure 订阅,请注册试用版 Azure 订阅If you don't have an Azure subscription, sign up for a trial Azure subscription.

  • SFTP 服务器地址和帐户凭据,便于工作流访问 SFTP 帐户。Your SFTP server address and account credentials, so your workflow can access your SFTP account. 还需要有权访问 SSH 私钥和 SSH 私钥密码。You also need access to an SSH private key and the SSH private key password. 若要在上传大文件时使用分块,你需要对 SFTP 服务器上的根文件夹具有读写权限。To upload large files using chunking, you need both read and write access for the root folder on your SFTP server. 否则,你将收到“401 未授权”错误。Otherwise, you get a "401 Unauthorized" error.

    SFTP-SSH 连接器支持私钥身份验证和密码身份验证。The SFTP-SSH connector supports both private key authentication and password authentication. 然而,SFTP-SSH 连接器仅支持以下私钥、格式、算法和指纹:However, the SFTP-SSH connector supports only these private key formats, algorithms, and fingerprints:

    • 私钥格式:采用 OpenSSH 和 ssh.com 格式的 RSA (Rivest Shamir Adleman) 和 DSA(数字签名算法)密钥。Private key formats: RSA (Rivest Shamir Adleman) and DSA (Digital Signature Algorithm) keys in both OpenSSH and ssh.com formats. 如果私钥为 PuTTY (.ppk) 文件格式,请先将密钥转换为 OpenSSH (.pem) 文件格式If your private key is in PuTTY (.ppk) file format, first convert the key to the OpenSSH (.pem) file format.
    • 加密算法:DES-EDE3-CBC、DES-EDE3-CFB、DES-CBC、AES-128-CBC、AES-192-CBC 和 AES-256-CBCEncryption algorithms: DES-EDE3-CBC, DES-EDE3-CFB, DES-CBC, AES-128-CBC, AES-192-CBC, and AES-256-CBC
    • 指纹:MD5Fingerprint: MD5

    在向工作流添加所需的 SFTP-SSH 触发器或操作之后,必须提供 SFTP 服务器的连接信息。After you add an SFTP-SSH trigger or action to your workflow, you have to provide connection information for your SFTP server. 为此连接提供 SSH 密钥时,请勿手动输入或编辑密钥,否则可能导致连接失败。When you provide your SSH private key for this connection, *don't manually enter or edit the key _, which might cause the connection to fail. 而是确保从 SSH 私钥文件中复制密钥,并将该密钥粘贴到连接详细信息中。Instead, make sure that you copy the key from your SSH private key file, and _ paste* that key into the connection details. 有关详细信息,请参阅本文后面的使用 SSH 连接到 SFTP 部分。For more information, see the Connect to SFTP with SSH section later this article.

  • 有关如何创建逻辑应用的基本知识Basic knowledge about how to create logic apps

  • 要在其中访问 SFTP 帐户的逻辑应用工作流。The logic app workflow where you want to access your SFTP account. 若要从 SFTP-SSH 触发器开始,请创建一个空白逻辑应用工作流To start with an SFTP-SSH trigger, create a blank logic app workflow. 若要使用 SFTP-SSH 操作,请使用另一个触发器(例如“重复”触发器)启动工作流。To use an SFTP-SSH action, start your workflow with another trigger, for example, the Recurrence trigger.

SFTP-SSH 触发器的工作原理How SFTP-SSH triggers work

轮询行为Polling behavior

SFTP-SSH 触发器会轮询 SFTP 文件系统并查找自上次轮询以来已更改的任何文件。SFTP-SSH triggers poll the SFTP file system and look for any file that changed since the last poll. 某些工具允许保留文件更改时的时间戳。Some tools let you preserve the timestamp when the files change. 在这种情况下,必须禁用此功能才能让触发器正常工作。In these cases, you have to disable this feature so your trigger can work. 下面是一些常见设置:Here are some common settings:

SFTP 客户端SFTP client 操作Action
WinscpWinscp 转到“选项” > “首选项” > “传输” > “编辑” > “保留时间戳” > “禁用” Go to Options > Preferences > Transfer > Edit > Preserve timestamp > Disable
FileZillaFileZilla 转到“传输” > “保留已传输文件的时间戳” > “禁用” Go to Transfer > Preserve timestamps of transferred files > Disable

当触发器找到新文件时,会检查该新文件是否完整,以及是否未部分写入。When a trigger finds a new file, the trigger checks that the new file is complete, and not partially written. 例如,当触发器检查文件服务器时,可能正在更改某个文件。For example, a file might have changes in progress when the trigger checks the file server. 为了避免返回部分写入的文件,该触发器会记录具有最近更改的文件的时间戳,但不会立即返回该文件。To avoid returning a partially written file, the trigger notes the timestamp for the file that has recent changes, but doesn't immediately return that file. 仅当再次轮询服务器时,触发器才会返回该文件。The trigger returns the file only when polling the server again. 有时,此行为可能会导致延迟,长达触发器轮询间隔的两倍。Sometimes, this behavior might cause a delay that is up to twice the trigger's polling interval.

触发器重复周期移动和偏移Trigger recurrence shift and drift

你需要首先为其创建连接的基于连接的触发器(例如 SFTP SSH 触发器)不同于在 Azure 逻辑应用中以原生方式运行的内置触发器,如重复周期触发器Connection-based triggers where you need to create a connection first, such as the SFTP-SSH trigger, differ from built-in triggers that run natively in Azure Logic Apps, such as the Recurrence trigger. 在基于连接的周期性触发器中,重复周期计划不是控制执行的唯一驱动因素,并且时区只确定初始开始时间。In recurring connection-based triggers, the recurrence schedule isn't the only driver that controls execution, and the time zone only determines the initial start time. 后续运行取决于定期计划、上一次触发器执行以及其他可能导致运行时间发生偏差或产生意外行为的因素。Subsequent runs depend on the recurrence schedule, the last trigger execution, and other factors that might cause run times to drift or produce unexpected behavior. 例如,当夏令时 (DST) 开始和结束时,意外的行为可能包括无法维持指定的时间表。For example, unexpected behavior can include failure to maintain the specified schedule when daylight saving time (DST) starts and ends. 若要确保重复周期时间在 DST 生效时不会变化,请手动调整重复周期。To make sure that the recurrence time doesn't shift when DST takes effect, manually adjust the recurrence. 这样一来,工作流将继续在预期时间运行。That way, your workflow continues to run at the expected time. 否则,开始时间将在 DST 开始时向前移动 1 小时,在 DST 结束时向后移动 1 小时。Otherwise, the start time shifts one hour forward when DST starts and one hour backward when DST ends. 有关详细信息,请参阅基于连接的触发器的重复周期For more information, see Recurrence for connection-based triggers.

将基于 PuTTY 的密钥转换为 OpenSSHConvert PuTTY-based key to OpenSSH

PuTTY 格式和 OpenSSH 格式使用不同的文件扩展名。The PuTTY format and OpenSSH format use different file name extensions. PuTTY 格式使用 .ppk 或 PuTTY 私钥,文件扩展名。The PuTTY format uses the .ppk, or PuTTY Private Key, file name extension. OpenSSH 格式使用 pem 或隐私增强邮件的文件扩展名。The OpenSSH format uses the .pem, or Privacy Enhanced Mail, file name extension. 如果你的私钥采用 PuTTY 格式,并且必须使用 OpenSSH 格式,请先按照以下步骤将密钥转换为 OpenSSH 格式:If your private key is in PuTTY format, and you have to use OpenSSH format, first convert the key to the OpenSSH format by following these steps:

基于 Unix 的 OSUnix-based OS

  1. 如果 PuTTY 工具尚未安装在系统上,请立即安装,例如:If you don't have the PuTTY tools installed on your system, do that now, for example:

    sudo apt-get install -y putty

  2. 运行此命令,以便创建一个可以与 SFTP-SSH 连接器配合使用的文件:Run this command, which creates a file that you can use with the SFTP-SSH connector:

    puttygen <path-to-private-key-file-in-PuTTY-format> -O private-openssh -o <path-to-private-key-file-in-OpenSSH-format>

    例如:For example:

    puttygen /tmp/sftp/my-private-key-putty.ppk -O private-openssh -o /tmp/sftp/my-private-key-openssh.pem

Windows OSWindows OS

  1. 下载最新的 PuTTY 生成器 (puttygen.exe) 工具(如果尚未这样做),然后启动该工具。If you haven't done so already, download the latest PuTTY Generator (puttygen.exe) tool, and then launch the tool.

  2. 在此屏幕上,选择“加载”。On this screen, select Load.

    选择“加载”

  3. 浏览到 PuTTY 格式的私钥文件,然后选择“打开”。Browse to your private key file in PuTTY format, and select Open.

  4. 在“转换”菜单中,选择“导出 OpenSSH 密钥”。 From the Conversions menu, select Export OpenSSH key.

    选择“导出 OpenSSH 密钥”

  5. 使用 .pem 文件扩展名保存该私钥文件。Save the private key file with the .pem file name extension.

注意事项Considerations

本部分介绍使用此连接器的触发器和操作时要查看的注意事项。This section describes considerations to review when you use this connector's triggers and actions.

使用不同的 SFTP 文件夹进行文件上传和处理Use different SFTP folders for file upload and processing

在 SFTP 服务器上,使用单独的文件夹来存储上传的文件,并使用触发器来监视这些文件以进行处理。On your SFTP server, use separate folders for storing uploaded files and for the trigger to monitor those files for processing. 否则,触发器将不会触发且行为不可预测,例如,跳过触发器处理的随机数量的文件。Otherwise, the trigger won't fire and behaves unpredictably, for example, skipping a random number of files that the trigger processes. 但是,这一要求意味着你需要一种在这些文件夹之间移动文件的方法。However, this requirement means that you need a way to move files between those folders.

如果发生此问题,请从触发器监视的文件夹中删除这些文件,并使用其他文件夹存储已上传的文件。If this trigger problem happens, remove the files from the folder that the trigger monitors, and use a different folder to store the uploaded files.

创建文件Create file

若要在 SFTP 服务器上创建文件,可以使用 SFTP-SSH“创建文件”操作。To create a file on your SFTP server, you can use the SFTP-SSH Create file action. 当此操作创建文件时,逻辑应用服务也会自动调用 SFTP 服务器来获取文件的元数据。When this action creates the file, the Logic Apps service also automatically calls your SFTP server to get the file's metadata. 但是,如果在逻辑应用服务调用获取元数据之前移动新创建的文件,则会收到 404 错误消息 'A reference was made to a file or folder which does not exist'However, if you move the newly created file before the Logic Apps service can make the call to get the metadata, you get a 404 error message, 'A reference was made to a file or folder which does not exist'. 若要在创建文件后跳过读取文件元数据的操作,请按照以下步骤添加并将“获取所有文件元数据”属性设置为“否”To skip reading the file's metadata after file creation, follow the steps to add and set the Get all file metadata property to No.

使用 SSH 连接到 SFTPConnect to SFTP with SSH

首次添加连接到服务或系统的触发器或操作时,逻辑应用设计器将提示你通过提供必要的信息(具体取决于连接)来创建连接,例如:When you add a trigger or action that connects to a service or system for the first time, the Logic App Designer prompts you to create a connection by providing the necessary information, which varies based on the connection, for example:

  • 要用于新连接的名称The name that you want to use for the new connection

  • 系统或服务器的名称The name for the system or server

  • 用户凭据或帐户凭据Your user or account credentials

  • 要使用的身份验证类型The authentication type to use

  1. 登录到 Azure 门户,在逻辑应用设计器中打开逻辑应用(如果尚未打开)。Sign in to the Azure portal, and open your logic app in Logic App Designer, if not open already.

  2. 对于空白逻辑应用,请在搜索框中输入 sftp ssh 作为筛选器。For blank logic apps, in the search box, enter sftp ssh as your filter. 在触发器列表下,选择所需的触发器。Under the triggers list, select the trigger you want.

    -或--or-

    对于现有逻辑应用,请在要添加操作的最后一个步骤下,选择“新建步骤”。For existing logic apps, under the last step where you want to add an action, select New step. 在搜索框中,输入 sftp ssh 作为筛选器。In the search box, enter sftp ssh as your filter. 在操作列表下,选择所需的操作。Under the actions list, select the action you want.

    若要在步骤之间添加操作,请将鼠标指针移到步骤之间的箭头上。To add an action between steps, move your pointer over the arrow between steps. 选择出现的加号 ( + ),然后选择“添加操作”。Select the plus sign (+) that appears, and then select Add an action.

  3. 为连接提供所需的详细信息。Provide the necessary details for your connection.

    重要

    在“SSH 私钥”属性中输入 SSH 私钥时,请遵循以下附加步骤,帮助确保提供此属性的完整正确值。 When you enter your SSH private key in the SSH private key property, follow these additional steps, which help make sure you provide the complete and correct value for this property. 无效的密钥会导致连接失败。An invalid key causes the connection to fail.

    可以使用任何文本编辑器。以下步骤以 Notepad.exe 为例,说明如何正确复制并粘贴密钥。Although you can use any text editor, here are sample steps that show how to correctly copy and paste your key by using Notepad.exe as an example.

    1. 在文本编辑器中打开 SSH 私钥文件。Open your SSH private key file in a text editor. 这些步骤以记事本为例。These steps use Notepad as the example.

    2. 在记事本的“编辑”菜单中,选择“全选”。 On the Notepad Edit menu, select Select All.

    3. 选择“编辑” > “复制”。Select Edit > Copy.

    4. 在 SFTP-SSH 触发器或操作中,粘贴已复制到“SSH 私钥”属性中的完整密钥,支持换行。In the SFTP-SSH trigger or action, paste the complete copied key in the SSH private key property, which supports multiple lines. 不要手动输入或编辑密钥。Don't manually enter or edit the key.

  4. 输入完连接详细信息后,请选择“创建”。After you finish entering the connection details, select Create.

  5. 现在,为所选触发器或操作提供所需的详细信息,然后继续生成逻辑应用的工作流。Now provide the necessary details for your selected trigger or action and continue building your logic app's workflow.

重写区块大小Override chunk size

若要重写分块使用的默认自适应行为,可以指定从 5 MB 到 50 MB 的固定区块大小。To override the default adaptive behavior that chunking uses, you can specify a constant chunk size from 5 MB to 50 MB.

  1. 在操作的右上角,选择省略号按钮(“…”),然后选择“设置” 。In the action's upper-right corner, select the ellipses button (...), and then select Settings.

    打开 SFTP-SSH 设置

  2. 在“内容传输”下的“区块大小”属性中,输入从 550 的整数值,例如 :Under Content Transfer, in the Chunk size property, enter an integer value from 5 to 50, for example:

    指定要改用的区块大小

  3. 完成后,选择“完成”。After you finish, select Done.

示例Examples

SFTP - SSH 触发器:添加或修改文件时SFTP - SSH trigger: When a file is added or modified

在 SFTP 服务器上添加或更改文件时,此触发器将启动工作流。This trigger starts a workflow when a file is added or changed on an SFTP server. 例如跟进操作,工作流可以使用条件来检查文件内容是否符合指定的标准。As example follow-up actions, the workflow can use a condition to check whether the file content meets specified criteria. 如果内容符合条件,则“获取文件内容”SFTP-SSH 操作可以获取内容,另一个 sftp SSH 操作可以将该文件放入 SFTP 服务器上的另一个文件夹中。If the content meets the condition, the Get file content SFTP-SSH action can get the content, and then another SFTP-SSH action can put that file in a different folder on the SFTP server.

企业示例:可以使用此触发器监视 SFTP 文件夹中表示客户订单的新文件。Enterprise example: You can use this trigger to monitor an SFTP folder for new files that represent customer orders. 然后,可以使用“获取文件内容”等 SFTP-SSH 操作来获取订单内容以做进一步处理,并将该订单存储在订单数据库中。You can then use an SFTP-SSH action such as Get file content so you get the order's contents for further processing and store that order in an orders database.

SFTP - SSH 操作:使用路径获取文件内容SFTP - SSH action: Get file content using path

此操作通过指定文件路径从 SFTP 服务器上的文件中获取内容。This action gets the content from a file on an SFTP server by specifying the file path. 例如,可以在前面的示例中添加触发器,并添加文件内容必须符合的条件。So for example, you can add the trigger from the previous example and a condition that the file's content must meet. 如果条件为 true,则可以运行获取内容的操作。If the condition is true, the action that gets the content can run.

排查问题Troubleshoot problems

本部分介绍常见错误或问题的可能解决方案。This section describes possible solutions to common errors or problems.

504 错误:“由于被连接方在一段时间后未正确响应,因此连接失败,或者,由于连接的主机未能响应,因此已建立的连接失败”,或者,“向 SFTP 服务器发出请求的用时已超过 '00:00:30' 秒”504 error: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond" or "Request to the SFTP server has taken more than '00:00:30' seconds"

在逻辑应用无法成功建立与 SFTP 服务器的连接时,可能会发生此错误。This error can happen when your logic app can't successfully establish a connection with the SFTP server. 此问题可能会有其他不同原因,因此请尝试以下故障排除选项:There might be different reasons for this problem, so try these troubleshooting options:

  • 连接超时为 20 秒。The connection timeout is 20 seconds. 请检查 SFTP 服务器的性能是否良好,并且中间设备(如防火墙)是否并未增加开销。Check that your SFTP server has good performance and intermediate devices, such as firewalls, aren't adding overhead.

  • 如果设置了防火墙,请确保将 托管连接器 IP 地址添加到已批准的列表。If you have a firewall set up, make sure that you add the Managed connector IP addresses to the approved list. 若要查找逻辑应用所在区域的 IP 地址,请参阅 Azure 逻辑应用的限制和配置To find the IP addresses for your logic app's region, see Limits and configuration for Azure Logic Apps.

  • 如果间歇性地发生此错误,请将 SFTP-SSH 操作上的“重试策略”设置更改为一个高于默认重试次数 (4) 的重试次数。If this error happens intermittently, change the Retry policy setting on the SFTP-SSH action to a retry count higher than the default four retries.

  • 请检查 SFTP 服务器是否对每个 IP 地址的连接数施加限制。Check whether SFTP server puts a limit on the number of connections from each IP address. 如果存在限制,则可能需要限制并发逻辑应用实例的数量。If a limit exists, you might have to limit the number of concurrent logic app instances.

  • 若要降低建立连接的成本,请在 SFTP 服务器的 SSH 配置中,将 ClientAliveInterval 属性增加到大约一小时。To reduce connection establishment cost, in the SSH configuration for your SFTP server, increase the ClientAliveInterval property to around one hour.

  • 请查看 SFTP 服务器日志,以检查来自逻辑应用的请求是否已到达 SFTP 服务器。Review the SFTP server log to check whether the request from logic app reached the SFTP server. 若要获取有关连接问题的详细信息,还可以在防火墙和 SFTP 服务器上运行网络跟踪。To get more information about the connectivity problem, you can also run a network trace on your firewall and your SFTP server.

404 错误:“引用了不存在的文件或文件夹”404 error: "A reference was made to a file or folder which does not exist"

如果工作流通过 SFTP-SSH“创建文件”操作在 SFTP 服务器上创建文件,但在逻辑应用服务可以获取该文件的元数据之前立即移动了文件,则可能会发生此错误。This error can happen when your workflow creates a file on your SFTP server with the SFTP-SSH Create file action, but immediately moves that file before the Logic Apps service can get the file's metadata. 当工作流运行“创建文件”操作时,逻辑应用服务会自动调用 SFTP 服务器来获取文件的元数据。When your workflow runs the Create file action, the Logic Apps service automatically calls your SFTP server to get the file's metadata. 但是,如果逻辑应用移动了该文件,逻辑应用服务将无法再找到该文件,因此你将收到 404 错误消息。However, if your logic app moves the file, the Logic Apps service can no longer find the file so you get the 404 error message.

如果无法避免或延迟移动文件,则可以在创建文件后跳过读取文件元数据的操作,方法是执行以下步骤:If you can't avoid or delay moving the file, you can skip reading the file's metadata after file creation instead by following these steps:

  1. 在“创建文件”操作中,打开“添加新参数”列表,选择“获取所有文件元数据”属性,并将值设置为“否” 。In the Create file action, open the Add new parameter list, select the Get all file metadata property, and set the value to No.

  2. 如果以后需要此文件元数据,可以使用“获取文件元数据”操作。If you need this file metadata later, you can use the Get file metadata action.

连接器参考Connector reference

有关此连接器的更多技术详细信息,例如触发器、操作和限制(如此连接器的 Swagger 文件所述),请参阅连接器的参考页For more technical details about this connector, such as triggers, actions, and limits as described by the connector's Swagger file, see the connector's reference page.

后续步骤Next steps