> 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_delete.md).

# ftp\_delete

Deletes a file or directory on the FTP/SFTP server. Must be used inside an `ftp_session` block.

```liquid
{% ftp_session host: "ftp.example.com", user: "myuser", password: "mypass" %}
  {% ftp_delete target: "/temp/old_file.csv" as result %}

  {% if result.ok %}
    {% log "File deleted" %}
  {% endif %}
{% endftp_session %}
```

#### Syntax

```liquid
{% ftp_delete target: "/path/to/file_or_directory" as result_variable %}
```

#### Parameters

| Parameter   | Required | Description                                       |
| ----------- | -------- | ------------------------------------------------- |
| `target`    | Yes      | Path to the file or directory to delete           |
| `recursive` | No       | Set to `true` to delete directories with contents |

#### Result Object

| Property | Type        | Description                                         |
| -------- | ----------- | --------------------------------------------------- |
| `ok`     | boolean     | `true` if deletion succeeded                        |
| `error`  | string/null | Error message if `ok` is `false`, `null` on success |

Example result:

```json
{
  "ok": true,
  "error": null
}
```

#### Examples

**Delete a single file:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_delete target: "/temp/report.csv" as result %}

  {% if result.ok %}
    {% log "File deleted successfully" %}
  {% else %}
    {% log result.error %}
  {% endif %}
{% endftp_session %}
```

**Delete an empty directory:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_delete target: "/old_folder" as result %}
{% endftp_session %}
```

**Delete directory with all contents (recursive):**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_delete target: "/temp/old_exports", recursive: true as result %}

  {% if result.ok %}
    {% log "Directory and all contents deleted" %}
  {% endif %}
{% endftp_session %}
```

**Clean up old files:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_list path: "/logs" as list_result %}

  {% assign cutoff = "now" | date: "%s" | minus: 604800 %}
  {% comment %} 604800 seconds = 7 days {% endcomment %}

  {% for file in list_result.files %}
    {% if file.modifiedAt < cutoff %}
      {% ftp_delete target: file.path as delete_result %}
      {% if delete_result.ok %}
        {% log "Deleted old file: " %}
        {% log file.name %}
      {% endif %}
    {% endif %}
  {% endfor %}
{% endftp_session %}
```

**Process, archive, then delete original:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_list path: "/inbox", pattern: "*.csv" as files %}

  {% for file in files.files %}
    {% ftp_download from: file.path as download %}

    {% if download.ok %}
      {% comment %} Process the file... {% endcomment %}
      {% assign content = download.file.name | content %}

      {% comment %} Delete original after successful processing {% endcomment %}
      {% ftp_delete target: file.path as delete_result %}

      {% if delete_result.ok %}
        {% log "Processed and removed: " %}
        {% log file.name %}
      {% endif %}
    {% endif %}
  {% endfor %}
{% endftp_session %}
```

#### Notes

* Must be used inside an `ftp_session` block
* Consumes 2 credits per operation
* Use `recursive: true` with caution - it permanently deletes all contents
* Cannot delete non-empty directories without `recursive: true`
* Operation cannot be undone


---

# 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_delete.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.
