ftp

Uses an FTP profile to list files on a remote FTP server, read file contents, or upload query results as a file.

Command properties

ItemDescription
Command typeDriver query or Transforming
Required permissionFTP profile usage permission
License usageCounted
Parallel executionNot supported
Distributed executionNot supported

Syntax

To list files:

ftp PROFILE ls [encoding=STR] PATH

To read file contents:

ftp PROFILE cat [format={text|csv|tsv|json}] [offset=LONG] [limit=LONG] [encoding=STR] [header=BOOL] PATH

To upload a file:

ftp PROFILE put [format={text|csv|tsv|json}] [fields=FIELD,...] [append=BOOL] [overwrite=BOOL] [encoding=STR] PATH

Options

format={text|csv|tsv|json}
File format (default: text)
  • text: Reads or writes one line as one record.
  • csv: Reads or writes in CSV format.
  • tsv: Reads or writes in tab-separated format.
  • json: Reads or writes in JSON format.
offset=LONG
Number of records to skip in the cat operation. Specify a non-negative integer. (default: 0)
limit=LONG
Maximum number of records to read in the cat operation. Specify a non-negative integer.
encoding=STR
File encoding (default: utf-8)
header=BOOL
Whether to use the first row of CSV or TSV files as a header in the cat operation. (default: f)
fields=FIELD,...
List of fields to write in the put operation. Separate with commas (,). If not specified, writes the line field. For JSON format, writes all fields if not specified.
append=BOOL
Whether to append content to an existing file in the put operation. Cannot be used together with the overwrite option. (default: f)
overwrite=BOOL
Whether to overwrite an existing file in the put operation. Cannot be used together with the append option. (default: f)

Target

PROFILE
FTP profile name. Specify the FTP connect profile registered in the system.
PATH
Path to the file or directory on the FTP server. In the cat operation, you can use a wildcard (*) in the file name.

Output fields

Output fields for the ls operation:

FieldTypeDescription
typestringEntry type. dir or file
namestringFile or directory name
file_sizelongFile size (bytes)
ownerstringFile owner
groupstringFile group
modified_attimestampLast modification time

Output fields for the cat operation depend on the format option. In text format, a line of text is assigned to the line field. In csv and tsv formats, fields are assigned based on headers or column indices. In json format, JSON key-value pairs are assigned as fields. The _file field containing the original file path is assigned in all formats.

Error codes

Parse errors
Error codeMessageDescription
40001missing-fieldThe command syntax is invalid
40002ftp-profile-not-foundThe specified FTP profile is not registered
40003no-permissionThe current user does not have permission to use the profile
40004invalid-offsetThe offset value is not an integer
40005invalid-limitThe limit value is not an integer
40006invalid-ftp-commandThe operation is not one of ls, cat, or put
40007invalid-ftp-file-formatThe format value is not one of text, csv, tsv, or json
40008invalid-encodingAn unsupported encoding is specified
40012choose-overwrite-or-appendBoth overwrite and append are specified together in the put operation
Runtime errors
Error codeMessageDescriptionPost-processing
40009invalid-wildcard-pathA wildcard is used in the directory portion of the pathStops query
40010cannot-read-directoryThe target of the cat operation is a directoryStops query
40011cannot-executeAn error occurred during FTP server connection or file processingCloses FTP connection
40013cannot-overwrite-fileAn existing file is present in the put operation but overwrite is not enabledStops query
40014invalid-fieldsDuring put with append, the fields differ from those already written to the fileStops query

Description

The ftp command communicates with a remote FTP server using an FTP profile registered in the system. Three operations are supported:

  • ls: Lists files and directories at the specified path. Directories are listed first, followed by files, sorted alphabetically. The ls operation acts as a driver query.
  • cat: Reads the contents of the file at the specified path and converts them into records. You can use a wildcard (*) in the file name. The cat operation acts as a driver query.
  • put: Writes input records to a file at the specified path. The put operation acts as a transforming query and passes input records unchanged to the next command. The put operation runs on the Control Node (reducer).

You can use query parameters (${}) in profile names and file paths.

Examples

  1. List files on an FTP server

    ftp myprofile ls /data/logs
    

    Lists files in the /data/logs directory using the myprofile FTP profile.

  2. Read a text file from an FTP server

    ftp myprofile cat /data/logs/access.log
    

    Reads the /data/logs/access.log file in text format and converts each line into a record.

  3. Read a CSV file with a header

    ftp myprofile cat format=csv header=t /data/logs/report.csv
    

    Reads a CSV file using the first row as field names.

  4. Read multiple JSON files using a wildcard

    ftp myprofile cat format=json /data/logs/*.json
    

    Reads all files with the .json extension from the /data/logs/ directory.

  5. Upload query results to an FTP server as a CSV file

    table duration=1d web_logs
    | stats count by method
    | ftp myprofile put format=csv fields=method,count /data/report.csv
    

    Uploads query results in CSV format to the FTP server.

  6. Append content to an existing file

    table duration=1h web_logs
    | ftp myprofile put format=json append=t /data/logs/combined.json
    

    Appends content to an existing file in JSON format.