# ftp

{% hint style="info" %}
Deprecated. Use [ftp\_session](/liquid/tags/ftp_session.md), [ftp\_list](/liquid/tags/ftp_list.md), [ftp\_upload](/liquid/tags/ftp_upload.md), [ftp\_download](/liquid/tags/ftp_download.md), [ftp\_delete](/liquid/tags/ftp_delete.md) tags instead
{% endhint %}

Set of utilities helping you to access, download, move or delete files in FTP or sFTP server.

{% hint style="info" %}
By default when an error is encountered in any of the ftp operations - a critical error is thrown and script terminates the execution. You can set the parameter exitOnError to false to continue executing the script anytime a FTP error is detected.
{% endhint %}

#### Download

```liquid
{% json ftp_params %}
  {
    "mode": "download",
    "host": "ftp.com",
    "user": "user@ftp.com",
    "password": "pass123",
    "path": "/",
    "port": 21,
    "fileName": "ftp_file.csv",
    "file": "local_file.csv",
    "exitOnError": false
  }
{% endjson %}

{% assign result = ftp_params | ftp %}
```

Above snippet downloads remove file called `ftp_file.csv` and saves it in your storage as local\_file.csv.

Next you can access this file by adding following commands:

```
{% assign file_content = "local_file.csv" | content %}
{% assign csv_parsed = file_content | parse_csv %}
```

Your `csv_parsed` variable would now contain an array of object with csv columns as property names.

#### List

```
{% json ftp_params %}
  {
    "mode": "list",
    "host": "ftp.com",
    "user": "user@ftp.com",
    "password": "pass123",
    "path": "/",
    "port": 21
  }
{% endjson %}

{% assign result = ftp_params | ftp %}
```

Gets all files from remote ftp server. You can next use `for` loop to iterate over available files.

```
{% for file in result.files %}
    {{file | log }}
{% endfor %}
```

Above snippet would log all files on FTP server under directory specified in `path` parameter.

#### Move

```
{% json ftp_params %}
  {
    "mode": "move",
    "host": "ftp.com",
    "user": "user@ftp.com",
    "password": "pass123",
    "path": "/",
    "port": 21,
    "fileName": "ftp_file.csv",
    "newPath": "/processed/ftp_file.csv"
  }
{% endjson %}

{% assign result = ftp_params | ftp %}
```

Moves file `ftp_file.csv` from `/` to `/processed/`

#### Delete

```
{% json ftp_params %}
  {
    "mode": "delete",
    "host": "ftp.com",
    "user": "user@ftp.com",
    "password": "pass123",
    "path": "/",
    "port": 21,
    "fileName": "ftp_file.csv"
  }
{% endjson %}

{% assign result = ftp_params | ftp %}
```

Deletes file `ftp_file.csv` from `/` directory.

#### Upload

```
{% capture sample_content %}
id,quantity
1234567,200
{% endcapture %}

{% json ftp_params %}
  {
    "mode": "upload",
    "host": "ftp.com",
    "user": "user@ftp.com",
    "password": "pass123",
    "path": "/",
    "port": 21,
    "content": {{ sample_content | json }},
    "fileName": "sample_upload.csv"
  }
{% endjson %}

{% assign result = ftp_params | ftp %}
```

Uploads file with defined content to ftp. File is saved as `sample_upload.txt`

#### sFTP servers

To access sFTP servers additional paramter sftp set to true is expected. To list files on sFTP server following snippet could be used.

```
{% json sftp_params %}
  {
    "mode": "list",
    "host": "ftp.com",
    "user": "user@ftp.com",
    "password": "pass123",
    "path": "/",
    "port": 21,
    "sftp": true
  }
{% endjson %}

{% assign result = sftp_params | ftp %}
```


---

# 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/filters/ftp.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.
