> For the complete documentation index, see [llms.txt](https://docs.datajet-app.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datajet-app.com/liquid/tags/ftp_session.md).

# ftp\_session

Establishes a connection to an FTP or SFTP server. All FTP operations (`ftp_list`, `ftp_download`, `ftp_upload`, `ftp_move`, `ftp_delete`) must be placed inside this block.

```liquid
{% ftp_session host: "ftp.example.com", user: "username", password: "password" %}
  {% ftp_list path: "/data" as files %}
  {% log files %}
{% endftp_session %}
```

#### Syntax

```liquid
{% ftp_session host: "hostname", user: "username", password: "password" %}
  ... FTP operations ...
{% endftp_session %}
```

#### Parameters

| Parameter  | Required | Default              | Description                       |
| ---------- | -------- | -------------------- | --------------------------------- |
| `host`     | Yes      | -                    | FTP server hostname               |
| `user`     | Yes      | -                    | Username for authentication       |
| `password` | Yes      | -                    | Password for authentication       |
| `port`     | No       | 21 (FTP) / 22 (SFTP) | Server port                       |
| `sftp`     | No       | `false`              | Set to `true` for SFTP connection |

#### Examples

**Standard FTP connection:**

```liquid
{% ftp_session host: "ftp.example.com", user: "myuser", password: "mypass" %}
  {% ftp_list path: "/" as result %}
  {% log result.files %}
{% endftp_session %}
```

**SFTP connection:**

```liquid
{% ftp_session host: "sftp.example.com", user: "myuser", password: "mypass", sftp: true %}
  {% ftp_download from: "/exports/data.csv" as result %}
  {% log result %}
{% endftp_session %}
```

**Custom port:**

```liquid
{% ftp_session host: "ftp.example.com", user: "myuser", password: "mypass", port: 2121 %}
  {% ftp_list path: "/files" as result %}
{% endftp_session %}
```

**Using variables for credentials:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD, sftp: FTP_SFTP %}
  {% ftp_list path: FTP_PATH as result %}
  {% for file in result.files %}
    {% log file.name %}
  {% endfor %}
{% endftp_session %}
```

#### Notes

* Connection is automatically closed when the block ends
* All FTP operation tags must be nested inside `ftp_session`
* Supports both FTP (port 21) and SFTP (port 22)
* Connection timeout is 5 minutes by default
* Each FTP operation inside the session consumes 2 credits


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.datajet-app.com/liquid/tags/ftp_session.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
