本页内容
Sommatic 文档
打开控制台

FTP/SFTP Client

通过 FTP/SFTP 传输文件。

以 Markdown 查看
在以下应用中打开
输入与输出 可用 io.ftp 版本 1.0.0 执行方式: async

通过 FTP、FTPS 或 SFTP 列出、上传、下载或删除单个远程文件,凭据在服务器端解析。

工作原理

  1. 解析配置。connection_id、operation(默认 list)、remotePath 和 fileContent 缺失时回退到输入 payload 中的同名键。
  2. 解析凭据:host(默认 127.0.0.1)、port、protocol 和 secure 取自凭据配置;username 和 password 取自凭据密钥。
  3. 选择协议:端口为 22 或 2222、或 protocol 为 sftp 时使用 SFTP;否则使用 FTP(secure 为 true 时使用 FTPS)。凭据未设置端口时,SFTP 使用 22,FTP 使用 21。
  4. 执行操作:list(列出 remotePath 目录)、upload(将 fileContent 写入 remotePath)、download(以 UTF-8 文本读取 remotePath)或 delete。
  5. 从 out 返回 { result },关闭连接,并将协议错误发送到 error。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-download-orders",
  "label": "Download orders file",
  "operator_slug": "io.ftp",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "operation": "download",
    "remotePath": "/outbound/orders-{{ $json.date }}.csv"
  }
}

配置

connection_id string 必填

FTP/SFTP 服务器的凭据。接受 `basic-auth`(用户名 + 密码 + 主机 + 端口)或 `connection-string`(ftp:// / sftp:// URI)类型的凭据。

operation string 必填

默认值: list

可选值: listuploaddownloaddelete

remotePath string 可选
localPath string 可选

用于上传/下载

fileContent string 可选

用于上传的直接内容

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

connection_id
接受 basic-auth 凭据:其配置包含 host、port、protocol(设为 sftp 可强制使用 SFTP)和 secure,密钥包含 username 和 password。connection-string 类型的密钥(ftp:// URI)不会被解析,主机和端口必须写在凭据配置中。以 { 开头的值会被解析为内联 JSON { config, credentials },而非凭据 id;仅限本地测试使用。
localPath
已声明但被忽略:上传读取 fileContent,下载在输出中返回内容,不会读写本地磁盘。
remotePath
为空时,list 使用 /(FTP)或 .(SFTP)。
port 代码会读取,但未声明
未声明,仅作提示读取:凭据未设置端口且节点配置为 port: 22 时,使用端口 22 的 SFTP。

输出端口

out 默认

操作成功。list 时 result 为条目数组,download 时为 { content },upload 时为 { uploaded: true, path },delete 时为 { deleted: true }。FTP 列表条目包含库提供的文件信息(name、type:1 = 文件,2 = 目录、size、rawModifiedAt 等);SFTP 条目仅含 name、type 和 size。

数据
{
  "result": [
    {
      "name": "orders-2026-11-25.csv",
      "type": 1,
      "size": 18342
    },
    {
      "name": "archive",
      "type": 2,
      "size": 4096
    }
  ]
}
error

登录、传输或路径错误,操作缺少参数,不支持的操作,或 SFTP 连接提前关闭。

数据
{
  "error": "remotePath is required for download"
}

在表达式中

后续节点可通过 $("FTP/SFTP Client").item.json.<路径> 读取此节点输出中的内容(请把 FTP/SFTP Client 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("FTP/SFTP Client").item.json.resultobject= […] (2)FTP 操作结果(例如列表或成功状态)

错误

消息 端口 原因与处理
connection_id is required error 在连接前抛出,因此引擎会将该节点判定为失败(若无 flow.try 作用域捕获,整个运行也会失败)。请选择 FTP 或 SFTP 凭据。
Failed to resolve connection <connection_id>: <detail> error 凭据不存在或此工作流无权使用。同样会抛出异常,因此在 flow.try 作用域之外运行会失败。
fileContent is required for upload error FTP upload 缺少内容(路径缺失时 FTP 对应报 remotePath is required for upload 和 remotePath is required for download;SFTP 报 fileContent is required)。
Unsupported operation: <operation> error operation 不是 list、upload、download 或 delete。
SSH connection closed error SFTP 服务器在操作完成前关闭了连接,通常是因为登录被拒绝。

输入契约

connection_id string 必填
operation string 必填
remotePath string 可选
localPath string 可选
fileContent string 可选

输出契约

result object 可选

FTP 操作结果(例如列表或成功状态)

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "io.ftp",
  "name": "FTP/SFTP Client",
  "category": "io",
  "version": "1.0.0",
  "description": "Transfer files via FTP/SFTP.",
  "capabilities": [
    "storage",
    "ftp",
    "sftp"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "FTP / SFTP Credential",
        "description": "Credential for the FTP/SFTP server. Accepts credentials of type `basic-auth` (username + password + host + port) or `connection-string` (ftp:// / sftp:// URI).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "basic-auth",
            "connection-string"
          ],
          "types": [
            "ftp",
            "sftp"
          ]
        }
      },
      "operation": {
        "type": "string",
        "enum": [
          "list",
          "upload",
          "download",
          "delete"
        ],
        "default": "list"
      },
      "remotePath": {
        "type": "string"
      },
      "localPath": {
        "type": "string",
        "description": "For upload/download"
      },
      "fileContent": {
        "type": "string",
        "description": "Direct content for upload"
      }
    },
    "required": [
      "connection_id",
      "operation"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "operation": {
        "type": "string"
      },
      "remotePath": {
        "type": "string"
      },
      "localPath": {
        "type": "string"
      },
      "fileContent": {
        "type": "string"
      }
    },
    "required": [
      "connection_id",
      "operation"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object",
        "description": "FTP operation result (e.g. list, or success)"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Result",
      "description": "Operation result",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Transfer failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io"
  ],
  "tags": [
    "storage",
    "legacy"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

执行

执行方式
async
有状态
否
凭据
在服务器端根据 connection_id 解析,密钥不会进入工作流。
能力
storageftpsftp
标签
storagelegacy

说明与限制

  • 下载内容以 UTF-8 文本返回,二进制文件会损坏。上传时 fileContent 以文本发送。
  • SFTP 握手最多等待 15 秒。FTP 除库默认值外没有显式超时。不会重试。
  • 凭据密钥在运行时于服务器端解析,不会出现在输出中。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

安装 Sommatic AI CLI,并为检测到的智能体配置合适的插件。

npx @sommatic/cli agent setup
智能体如何读取本文档