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
40001잘못된 ftp 명령어 문법입니다. ftp [프로파일] [오퍼레이터] [확장 옵션]The command syntax is invalid
40002FTP 프로파일이 존재하지 않습니다.The specified FTP profile is not registered
40003FTP 프로파일을 사용할 권한이 없습니다.The current user does not have permission to use the profile
40004유효하지 않은 ftp offset 옵션입니다. 0 이상의 정수를 사용해야 합니다.The offset value is not an integer
40005유효하지 않은 ftp limit 옵션입니다. 0 이상의 정수를 사용해야 합니다.The limit value is not an integer
40006유효하지 않은 ftp 명령어 오퍼레이터입니다.The operation is not one of ls, cat, or put
40007유효하지 않은 ftp 파일 포맷입니다.The format value is not one of text, csv, tsv, or json
40008잘못된 인코딩입니다.An unsupported encoding is specified
40012ftp put 명령어에서 overwrite 와 append 옵션은 동시에 사용할 수 없습니다.Both overwrite and append are specified together in the put operation
Runtime errors
Error codeMessageDescriptionPost-processing
40009파일 이름 외에는 와일드 카드를 사용할 수 없습니다.A wildcard is used in the directory portion of the pathStops query
40010ftp 조회 대상이 디렉터리입니다.The target of the cat operation is a directoryStops query
40011ftp 명령어를 실행할 수 없습니다.An error occurred during FTP server connection or file processingCloses FTP connection
40013ftp put 명령어에서 overwrite 옵션 없이 파일을 덮어 쓸 수 없습니다.An existing file is present in the put operation but overwrite is not enabledStops query
40014ftp put 명령어에서 기록할 필드 목록과 이미 파일에 기록된 필드 목록이 일치하지 않습니다.During 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.