# FTP/SFTP Client

> Transfer files via FTP/SFTP.

Source: https://docs.sommatic.ai/en/nodes/io.ftp/

- Slug: `io.ftp`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Transfer files via FTP/SFTP.

## Configuration

- `connection_id` (string, required): Credential for the FTP/SFTP server. Accepts credentials of type `basic-auth` (username + password + host + port) or `connection-string` (ftp:// / sftp:// URI).
- `operation` (string, required): Default: `list`. Allowed values: `list`, `upload`, `download`, `delete`.
- `remotePath` (string, optional)
- `localPath` (string, optional): For upload/download
- `fileContent` (string, optional): Direct content for upload

## Output ports

- `out` (default): Operation result
- `error`: Transfer failed

## Input contract

- `connection_id` (string, required)
- `operation` (string, required)
- `remotePath` (string, optional)
- `localPath` (string, optional)
- `fileContent` (string, optional)

## Output contract

- `result` (object, optional): FTP operation result (e.g. list, or success)

## In expressions

What a later node can read from this node's output with `$("FTP/SFTP Client").item.json.<path>` (write your node's label instead of `FTP/SFTP Client`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("FTP/SFTP Client").item.json.result` (object) = `[…] (2)`: FTP operation result (e.g. list, or success)


## How it works

Lists, uploads, downloads or deletes one remote file over FTP, FTPS or SFTP, using a credential resolved on the server.

1. Resolves the config. `connection_id`, `operation` (default `list`), `remotePath` and `fileContent` fall back to the same keys of the incoming payload.
2. Resolves the credential: `host` (default `127.0.0.1`), `port`, `protocol` and `secure` come from the credential config; `username` and `password` from its secret.
3. Chooses the protocol: SFTP when the port is 22 or 2222 or `protocol` is `sftp`; otherwise FTP (FTPS when `secure` is true). Without a port in the credential it uses 22 for SFTP and 21 for FTP.
4. Runs the operation: `list` (directory listing of `remotePath`), `upload` (writes `fileContent` to `remotePath`), `download` (reads `remotePath` as UTF-8 text) or `delete`.
5. Returns `{ result }` through `out`, closes the connection, and sends protocol errors to `error`.

## In a workflow

### Node

```json
{
  "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"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "result": {
      "content": "order_id,amount\nord_123,250.00\n"
    }
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The operation succeeded. `result` is an array of entries for `list`, `{ content }` for `download`, `{ uploaded: true, path }` for `upload` and `{ deleted: true }` for `delete`. FTP list entries carry the library's file info (`name`, `type` 1 = file, 2 = directory, `size`, `rawModifiedAt`, …); SFTP entries carry only `name`, `type` and `size`.

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

### `error`

Login, transfer or path errors, a missing argument for the operation, an unsupported operation, or an SFTP connection that closed early.

```json
{
  "error": "remotePath is required for download"
}
```

## Behaviour in the code

- `connection_id`: Accepts `basic-auth` credentials whose config holds `host`, `port`, `protocol` (`sftp` to force SFTP) and `secure`, and whose secret holds `username` and `password`. A `connection-string` secret (an `ftp://` URI) is not parsed: host and port must be in the credential config. A value starting with `{` is parsed as inline JSON `{ config, credentials }` instead of a credential id; use it only for local tests.
- `localPath`: Declared but ignored: uploads read `fileContent`, downloads return the content in the output. Nothing is read from or written to the local disk.
- `remotePath`: `list` uses `/` (FTP) or `.` (SFTP) when empty.
- `port`: Not declared. Read only as a hint: when the credential has no port and the node config has `port: 22`, SFTP on port 22 is used.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `connection_id is required` | `error` | Thrown before the worker connects, so the engine fails the node (and the run, unless a `flow.try` scope catches it). Select an FTP or SFTP credential. |
| `Failed to resolve connection <connection_id>: <detail>` | `error` | The credential does not exist or cannot be used by this workflow. Also thrown, so the run fails outside a `flow.try` scope. |
| `fileContent is required for upload` | `error` | FTP `upload` without content (`remotePath is required for upload` and `remotePath is required for download` are the FTP equivalents for the path; SFTP reports `fileContent is required`). |
| `Unsupported operation: <operation>` | `error` | `operation` is not `list`, `upload`, `download` or `delete`. |
| `SSH connection closed` | `error` | The SFTP server closed the connection before the operation finished, typically after a rejected login. |

## Notes and limits

- Downloads are returned as UTF-8 text: binary files are corrupted. Uploads send `fileContent` as text.
- SFTP waits up to 15 s for the handshake. FTP has no explicit timeout beyond the library defaults. There are no retries.
- The credential secret is resolved on the server at run time and never appears in the output.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "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
    }
  }
}
```

### config_schema

```json
{
  "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

```json
{
  "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

```json
{
  "type": "object",
  "properties": {
    "result": {
      "type": "object",
      "description": "FTP operation result (e.g. list, or success)"
    }
  }
}
```

### ports

```json
[
  {
    "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
  }
]
```
