# ftp

{% hint style="info" %}
Deprecated. Use [ftp\_session](https://docs.datajet-app.com/liquid/tags/ftp_session), [ftp\_list](https://docs.datajet-app.com/liquid/tags/ftp_list), [ftp\_upload](https://docs.datajet-app.com/liquid/tags/ftp_upload), [ftp\_download](https://docs.datajet-app.com/liquid/tags/ftp_download), [ftp\_delete](https://docs.datajet-app.com/liquid/tags/ftp_delete) 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.&#x20;
{% 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.&#x20;

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.&#x20;

#### 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.&#x20;

```
{% 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 %}
```
