您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure 逻辑应用创建、监视和管理 FTP 文件Create, monitor, and manage FTP files by using Azure Logic Apps

使用 Azure 逻辑应用和 FTP 连接器,可以创建自动化的任务和工作流,用于通过 FTP 服务器上的帐户创建、监视、发送和接收文件以及执行其他操作,例如:With Azure Logic Apps and the FTP connector, you can create automated tasks and workflows that create, monitor, send, and receive files through your account on an FTP server, along with other actions, for example:

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

可以使用触发器从 FTP 服务器获取响应,并使输出可用于其他操作。You can use triggers that get responses from your FTP server and make the output available to other actions. 可以使用逻辑应用中的运行操作对 FTP 服务器上的文件进行管理。You can use run actions in your logic apps for managing files on your FTP server. 还可以让其他操作使用来自 FTP 操作的输出。You can also have other actions use the output from FTP actions. 例如,如果你定期从 FTP 服务器获取文件,则可以使用 Office 365 Outlook 连接器或 Outlook.com 连接器发送有关这些文件及其内容的电子邮件。For example, if you regularly get files from your FTP server, you can send email about those files and their content by using the Office 365 Outlook connector or Outlook.com connector. 如果不熟悉逻辑应用,请查看什么是 Azure 逻辑应用If you're new to logic apps, review What is Azure Logic Apps.

限制Limitations

  • FTP 连接器仅支持显式 FTP over TLS/SSL (FTPS),与隐式 FTPS 不兼容。The FTP connector supports only explicit FTP over TLS/SSL (FTPS) and isn't compatible with implicit FTPS.

  • 默认情况下,FTP 操作可以读取或写入 50 MB 或更小 的文件。By default, FTP actions can read or write files that are 50 MB or smaller. 若要处理大于 50 MB 的文件,FTP 操作支持消息分块To handle files larger than 50 MB, FTP actions support message chunking. 获取文件内容 操作隐式使用分块。The Get file content action implicitly uses chunking.

  • FTP 触发器不支持分块。FTP triggers don't support chunking. 请求文件内容时,触发器仅选择 50 MB 或更小的文件。When requesting file content, triggers select only files that are 50 MB or smaller. 若要获取大于 50 MB 的文件,请遵循以下模式:To get files larger than 50 MB, follow this pattern:

    • 使用返回文件属性的 FTP 触发器,如“添加或修改文件时(仅属性)”。Use an FTP trigger that returns file properties, such as When a file is added or modified (properties only).

    • 跟随触发器执行 FTP 获取文件内容 操作,该操作读取完整文件并隐式使用分块。Follow the trigger with the FTP Get file content action, which reads the complete file and implicitly uses chunking.

  • 如果你有本地 FTP 服务器,请考虑创建集成服务环境 (ISE) 或使用 Azure 应用服务混合连接,这能让你在不使用本地数据网关的情况下访问本地数据源。If you have an on-premises FTP server, consider creating an integration service environment (ISE) or using Azure App Service Hybrid connections, which both let you access on-premises data sources without using an on-premises data gateway.

FTP 触发器的工作原理How FTP triggers work

FTP 触发器的工作原理是轮询 FTP 文件系统并查找自上次轮询后已更改的任何文件。FTP triggers work by polling the FTP file system and looking for any file that was 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.

先决条件Prerequisites

  • Azure 订阅。An Azure subscription. 如果没有 Azure 订阅,请注册一个免费 Azure 帐户If you don't have an Azure subscription, sign up for a free Azure account.

  • FTP 主机服务器地址和帐户凭据Your FTP host server address and account credentials

    FTP 连接器需要可从 Internet 访问并设置为在 passive 模式下运行的 FTP 服务器。The FTP connector requires that your FTP server is accessible from the internet and set up to operate in passive mode. 你的凭据允许逻辑应用创建连接并访问你的 FTP 帐户。Your credentials let your logic app create a connection and access your FTP account.

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

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

连接到 FTPConnect to FTP

首次添加连接到服务或系统的触发器或操作时,逻辑应用设计器将提示你通过提供必要的信息(具体取决于连接)来创建连接,例如: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.

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

    -或--or-

    对于现有逻辑应用,请在要添加操作的最后一个步骤下,选择“新建步骤”,然后选择“添加操作” 。For existing logic apps, under the last step where you want to add an action, select New step, and then select Add an action. 在搜索框中,输入 ftp 作为筛选器。In the search box, enter ftp as your filter. 从“操作”列表中选择所需的操作。From the Actions list, select the action that 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 your connection information, and select Create.

  4. 提供所选触发器或操作的信息,然后继续构建逻辑应用的工作流。Provide the information for your selected trigger or action and continue building your logic app's workflow.

示例Examples

添加 FTP 触发器Add FTP trigger

当检测到 FTP 服务器上添加或更改了文件时,“添加或修改文件时(仅属性)”触发器将启动一个逻辑应用工作流。The When a file is added or modified (properties only) trigger starts a logic app workflow when the trigger detects that a file is added or changed on an FTP server. 例如,可以添加一个条件,用于检查文件内容,并根据该内容是否符合指定的条件,来确定是否要获取该内容。For example, you can add a condition that checks the file's content and decides whether to get that content, based on whether that content meets a specified condition. 最后可以添加一个操作,用于获取文件内容并将该内容放在 SFTP 服务器上的另一个文件夹中。Finally, you can add an action that gets the file's content, and put that content into a different folder on the SFTP server.

例如,可以使用此触发器监视 FTP 文件夹中描述客户订单的新文件。For example, you can use this trigger to monitor an FTP folder for new files that describe customer orders. 然后,你可以使用诸如“获取文件元数据”的 FTP 操作获取该新文件的属性,然后使用“获取文件内容”获取该文件的内容,以便进一步处理并将该订单存储在订单数据库中。You can then use an FTP action such as Get file metadata to get the properties for that new file, and then use Get file content to get the content from that file for further processing and store that order in an orders database.

以下示例展示了如何使用“添加或修改文件时(仅属性)”触发器。Here is an example that shows how to use the When a file is added or modified (properties only) trigger.

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

  2. 对于空白逻辑应用,请在搜索框中输入 ftp 作为筛选器。For blank logic apps, in the search box, enter ftp as your filter. 在触发器列表中选择此触发器:添加或修改字段时(仅属性)Under the triggers list, select this trigger: When a filed is added or modified (properties only)

    查找并选择 FTP 触发器

  3. 为连接提供所需的详细信息,然后选择“创建”。Provide the necessary details for your connection, and then select Create.

    默认情况下,此连接器将以文本格式传输文件。By default, this connector transfers files in text format. 若要以二进制格式传输文件,例如,在使用了编码的情况下,请选择“二进制传输”。To transfer files in binary format, for example, where and when encoding is used, select Binary Transport.

    创建到 FTP 服务器的连接

  4. 在“文件夹”框中,选择文件夹图标,以便显示列表。In the Folder box, select the folder icon so that a list appears. 若想查找要监视其中是否有新文件或已编辑文件的文件夹,请选择右箭头 (>),浏览到该文件夹并将其选中。To find the folder you want to monitor for new or edited files, select the right angle arrow (>), browse to that folder, and then select the folder.

    查找并选择要监视的文件夹

    所选文件夹将出现在“文件夹”框中。Your selected folder appears in the Folder box.

    所选文件夹将出现在“文件夹”属性中

  5. 保存逻辑应用。Save your logic app. 在设计器工具栏上选择“保存”。On the designer toolbar, select Save.

现在,逻辑应用已具有一个触发器,请添加在逻辑应用找到新文件或已编辑文件时要运行的操作。Now that your logic app has a trigger, add the actions you want to run when your logic app finds a new or edited file. 对于此示例,可以添加获取新内容或更新内容的 FTP 操作。For this example, you can add an FTP action that gets the new or updated content.

添加 FTP 操作Add FTP action

“获取文件元数据”操作获取 FTP 服务器上的文件的属性,“获取文件内容”操作根据 FTP 服务器上该文件的相关信息获取文件内容。The Get file metadata action gets the properties for a file that's on your FTP server and the Get file content action gets the file content based on the information about that file on your FTP server. 例如,你可以添加前面示例中的触发器,然后添加这些操作,用于在添加或编辑文件后获取该文件内容。For example, you can add the trigger from the previous example and these actions to get the file's content after that file is added or edited.

  1. 在该触发器或任何其他操作下,选择“新建步骤”。Under the trigger or any other actions, select New step.

  2. 在搜索框中,输入 ftp 作为筛选器。In the search box, enter ftp as your filter. 在操作列表中选择以下操作:获取文件元数据Under the actions list, select this action: Get file metadata

    选择“获取文件元数据”操作

  3. 如果已有到 FTP 服务器和帐户的连接,请转到下一步。If you already have a connection to your FTP server and account, go to the next step. 如果没有,请为连接提供所需的详细信息,然后选择“创建”。Otherwise, provide the necessary details for that connection, and then select Create.

    创建 FTP 服务器连接

  4. 在“获取文件元数据”操作出现后,在“文件”框中单击,以便显示动态内容列表 。After the Get file metadata action appears, click inside the File box so that the dynamic content list appears. 现可为先前步骤的输出结果选择属性。You can now select properties for the outputs from previous steps. 在动态内容列表中,在“获取文件元数据”下,选择“文件 Id 列表”属性,该属性引用在其中添加或更新了文件的集合。In the dynamic content list, under Get file metadata, select the List of Files Id property, which references the collection where the file was added or updated.

    查找并选择“文件 Id 列表”属性

    “文件 Id 列表”属性现在显示在“文件”框中 。The List of Files Id property now appears in the File box.

    选定的“文件 Id 列表”属性

  5. 现在,添加以下 FTP 操作:获取文件内容Now add this FTP action: Get file content

    查找并选择“获取文件内容”操作

  6. 在“获取文件内容”操作出现后,在“文件”框中单击,以便显示动态内容列表 。After the Get file content action appears, click inside the File box so that the dynamic content list appears. 现可为先前步骤的输出结果选择属性。You can now select properties for the outputs from previous steps. 在动态内容列表中,在“获取文件元数据”下,选择“Id”属性,该属性引用已添加或更新的文件。In the dynamic content list, under Get file metadata, select the Id property, which references the file that was added or updated.

    查找并选择“Id”属性

    “Id”属性现在显示在“文件”框中 。The Id property now appears in the File box.

    选定的“Id”属性

  7. 保存逻辑应用。Save your logic app.

测试逻辑应用Test your logic app

若要检查工作流是否返回了所需的内容,请添加另一个操作,该操作会向你发送上传的或更新的文件内容。To check that your workflow returns the content that you expect, add another action that sends you the content from the uploaded or updated file.

  1. 在“获取文件内容”操作下,添加一个可以向你发送文件内容的操作。Under the Get file content action, add an action that can send you the file's contents. 此示例为 Office 365 Outlook 添加“发送电子邮件”操作。This example adds the Send an email action for the Office 365 Outlook.

    添加用于发送电子邮件的操作

  2. 操作出现后,请提供信息并包含要测试的属性。After the action appears, provide the information and include the properties that you want to test. 例如,包含“文件内容”属性,在“获取文件内容”部分中选择“查看更多”后,该属性会显示在动态内容列表中 。For example, include the File content property, which appears in the dynamic content list after you select See more in the Get file content section.

    提供关于电子邮件操作的信息

  3. 保存逻辑应用。Save your logic app. 若要运行和触发逻辑应用,请在工具栏上选择“运行”,然后将文件添加到逻辑应用现在所监视的 FTP 文件夹中。To run and trigger the logic app, on the toolbar, select Run, and then add a file to the FTP folder that your logic app now monitors.

连接器参考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.

备注

对于集成服务环境 (ISE) 中的逻辑应用,此连接器的 ISE 标记版本使用 ISE 消息限制For logic apps in an integration service environment (ISE), this connector's ISE-labeled version uses the ISE message limits instead.

后续步骤Next steps