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
| Item | Description |
|---|---|
| Command type | Driver query or Transforming |
| Required permission | FTP profile usage permission |
| License usage | Counted |
| Parallel execution | Not supported |
| Distributed execution | Not supported |
Syntax
To list files:
To read file contents:
To upload a file:
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
catoperation. Specify a non-negative integer. (default:0) limit=LONG- Maximum number of records to read in the
catoperation. 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
catoperation. (default:f) fields=FIELD,...- List of fields to write in the
putoperation. Separate with commas (,). If not specified, writes thelinefield. For JSON format, writes all fields if not specified. append=BOOL- Whether to append content to an existing file in the
putoperation. Cannot be used together with theoverwriteoption. (default:f) overwrite=BOOL- Whether to overwrite an existing file in the
putoperation. Cannot be used together with theappendoption. (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
catoperation, you can use a wildcard (*) in the file name.
Output fields
Output fields for the ls operation:
| Field | Type | Description |
|---|---|---|
| type | string | Entry type. dir or file |
| name | string | File or directory name |
| file_size | long | File size (bytes) |
| owner | string | File owner |
| group | string | File group |
| modified_at | timestamp | Last 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 code | Message | Description |
|---|---|---|
| 40001 | 잘못된 ftp 명령어 문법입니다. ftp [프로파일] [오퍼레이터] [확장 옵션] | The command syntax is invalid |
| 40002 | FTP 프로파일이 존재하지 않습니다. | The specified FTP profile is not registered |
| 40003 | FTP 프로파일을 사용할 권한이 없습니다. | 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 |
| 40012 | ftp put 명령어에서 overwrite 와 append 옵션은 동시에 사용할 수 없습니다. | Both overwrite and append are specified together in the put operation |
Runtime errors
| Error code | Message | Description | Post-processing |
|---|---|---|---|
| 40009 | 파일 이름 외에는 와일드 카드를 사용할 수 없습니다. | A wildcard is used in the directory portion of the path | Stops query |
| 40010 | ftp 조회 대상이 디렉터리입니다. | The target of the cat operation is a directory | Stops query |
| 40011 | ftp 명령어를 실행할 수 없습니다. | An error occurred during FTP server connection or file processing | Closes FTP connection |
| 40013 | ftp put 명령어에서 overwrite 옵션 없이 파일을 덮어 쓸 수 없습니다. | An existing file is present in the put operation but overwrite is not enabled | Stops query |
| 40014 | ftp put 명령어에서 기록할 필드 목록과 이미 파일에 기록된 필드 목록이 일치하지 않습니다. | During put with append, the fields differ from those already written to the file | Stops 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. Thelsoperation 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. Thecatoperation acts as a driver query.put: Writes input records to a file at the specified path. Theputoperation acts as a transforming query and passes input records unchanged to the next command. Theputoperation runs on the Control Node (reducer).
You can use query parameters (${}) in profile names and file paths.
Examples
-
List files on an FTP server
ftp myprofile ls /data/logsLists files in the
/data/logsdirectory using themyprofileFTP profile. -
Read a text file from an FTP server
ftp myprofile cat /data/logs/access.logReads the
/data/logs/access.logfile in text format and converts each line into a record. -
Read a CSV file with a header
ftp myprofile cat format=csv header=t /data/logs/report.csvReads a CSV file using the first row as field names.
-
Read multiple JSON files using a wildcard
ftp myprofile cat format=json /data/logs/*.jsonReads all files with the
.jsonextension from the/data/logs/directory. -
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.csvUploads query results in CSV format to the FTP server.
-
Append content to an existing file
table duration=1h web_logs | ftp myprofile put format=json append=t /data/logs/combined.jsonAppends content to an existing file in JSON format.