ftp

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

Download

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

{% endjson %}

{% json ftp_params %}
  {
    "mode": "upload",
    "host": "ftp.com",
    "user": "user@ftp.com",
    "password": "pass123",
    "path": "/",
    "port": 21,
    "content": {{ sample_content | json }},
    "fileName": "sample_upload.txt"
  }
{% 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 %}

Last updated