# ftp\_upload

Uploads content or a file to the FTP/SFTP server. Must be used inside an `ftp_session` block.

```liquid
{% ftp_session host: "ftp.example.com", user: "myuser", password: "mypass" %}
  {% ftp_upload to: "/uploads/data.csv", content: csv_content as result %}

  {% if result.ok %}
    {% log "Upload successful" %}
  {% endif %}
{% endftp_session %}
```

#### Syntax

```liquid
{% ftp_upload to: "/path/to/destination", content: content_variable as result_variable %}
{% ftp_upload to: "/path/to/destination", file: "filename_in_storage" as result_variable %}
```

#### Parameters

| Parameter | Required | Description                               |
| --------- | -------- | ----------------------------------------- |
| `to`      | Yes      | Destination path on the FTP server        |
| `content` | Yes\*    | Raw content to upload                     |
| `file`    | Yes\*    | Name of file in DataJet storage to upload |

\*Either `content` or `file` is required, but not both.

#### Result Object

| Property    | Type        | Description                                         |
| ----------- | ----------- | --------------------------------------------------- |
| `ok`        | boolean     | `true` if upload succeeded                          |
| `error`     | string/null | Error message if `ok` is `false`, `null` on success |
| `file.name` | string      | Name of the uploaded file                           |

Example result:

```json
{
  "ok": true,
  "error": null,
  "file": {
    "name": "inventory.csv"
  }
}
```

#### Examples

**Upload text content:**

```liquid
{% capture csv_content %}name,sku,quantity
Product A,SKU001,100
Product B,SKU002,50{% endcapture %}

{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_upload to: "/imports/inventory.csv", content: csv_content as result %}

  {% if result.ok %}
    {% log "CSV uploaded successfully" %}
  {% else %}
    {% log result.error %}
  {% endif %}
{% endftp_session %}
```

**Upload JSON data:**

```liquid
{% json export_data %}
  {
    "products": {{ products | json }},
    "exported_at": "{{ 'now' | date: '%Y-%m-%d %H:%M:%S' }}"
  }
{% endjson %}

{% assign json_content = export_data | json %}

{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD, sftp: true %}
  {% ftp_upload to: "/data/products.json", content: json_content as result %}
{% endftp_session %}
```

**Upload file from DataJet storage:**

```liquid
{% ftp_session host: FTP_HOST, user: FTP_USER, password: FTP_PASSWORD %}
  {% ftp_upload to: "/backups/report.pdf", file: "generated_report.pdf" as result %}

  {% if result.ok %}
    {% log "File uploaded from storage" %}
  {% endif %}
{% endftp_session %}
```

**Upload to nested directory (auto-created):**

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

  {% ftp_upload to: destination, content: csv_data as result %}
  {% comment %} Directories /archives/2024/01/15/ will be created automatically {% endcomment %}
{% endftp_session %}
```

#### Notes

* Must be used inside an `ftp_session` block
* Consumes 2 credits per upload
* Directories in the destination path are created automatically if they don't exist
* Use `content` for raw text/data, use `file` for files already in DataJet storage
* Maximum content size depends on your plan limits
