# ftp\_move

Moves or renames a file 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_move from: "/inbox/data.csv", to: "/processed/data.csv" as result %}

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

#### Syntax

```liquid
{% ftp_move from: "/source/path", to: "/destination/path" as result_variable %}
```

#### Parameters

| Parameter | Required | Description              |
| --------- | -------- | ------------------------ |
| `from`    | Yes      | Current path of the file |
| `to`      | Yes      | New path for the file    |

#### Result Object

| Property | Type        | Description                                         |
| -------- | ----------- | --------------------------------------------------- |
| `ok`     | boolean     | `true` if move succeeded                            |
| `error`  | string/null | Error message if `ok` is `false`, `null` on success |
| `from`   | string      | Original file path                                  |
| `to`     | string      | New file path                                       |

Example result:

```json
{
  "ok": true,
  "error": null,
  "from": "/inbox/data.csv",
  "to": "/processed/data.csv"
}
```

#### Examples

**Move file to archive folder:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_move from: "/imports/orders.csv", to: "/archives/orders.csv" as result %}

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

**Rename a file:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% assign timestamp = "now" | date: "%Y%m%d_%H%M%S" %}
  {% assign new_name = "/data/report_" | append: timestamp | append: ".csv" %}

  {% ftp_move from: "/data/report.csv", to: new_name as result %}
{% endftp_session %}
```

**Process and archive files:**

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

  {% for file in list_result.files %}
    {% comment %} Download and process {% endcomment %}
    {% ftp_download from: file.path as download %}

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

      {% comment %} Move to processed folder {% endcomment %}
      {% assign archive_path = "/processed/" | append: file.name %}
      {% ftp_move from: file.path, to: archive_path as move_result %}

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

**Move to dated archive folder:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% assign today = "now" | date: "%Y-%m-%d" %}
  {% assign archive_folder = "/archives/" | append: today | append: "/" %}

  {% ftp_list path: "/completed" as files %}

  {% for file in files.files %}
    {% if file.type == "file" %}
      {% assign destination = archive_folder | append: file.name %}
      {% ftp_move from: file.path, to: destination as result %}
    {% endif %}
  {% endfor %}
{% endftp_session %}
```

#### Notes

* Must be used inside an `ftp_session` block
* Consumes 2 credits per operation
* Destination directories are created automatically if they don't exist
* Can be used to rename files by moving to same directory with different name
* Works for both files and directories


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
