Skip to content
Stand with Ukraine flag

FTP

The FTP Connector connects to an external FTP server, reads data from files at configured paths, and pushes it to ThingsBoard. It can also write data back to FTP files in response to attribute updates or RPC commands.

To enable this connector, add it to the connectors list in tb_gateway.json — see the General Configuration reference.

The connector reads its settings from a JSON file. Below is a full example:

{
"host": "0.0.0.0",
"port": 21,
"TLSSupport": false,
"security": {
"type": "basic",
"username": "admin",
"password": "admin"
},
"paths": [
{
"devicePatternName": "asd",
"devicePatternType": "Device",
"delimiter": ",",
"path": "fol/*_hello*.txt",
"readMode": "FULL",
"maxFileSize": 5,
"pollPeriod": 5,
"txtFileDataView": "SLICED",
"withSortingFiles": true,
"attributes": [
{ "key": "temp", "value": "[1:]" },
{ "key": "tmp", "value": "[0:1]" }
],
"timeseries": [
{ "type": "int", "key": "[0:1]", "value": "[0:1]" },
{ "type": "int", "key": "temp", "value": "[1:]" }
]
}
],
"attributeUpdates": [
{
"path": "fol/hello.json",
"deviceNameFilter": ".*",
"writingMode": "WRITE",
"valueExpression": "{'${attributeKey}':'${attributeValue}'}"
}
],
"serverSideRpc": [
{
"deviceNameFilter": ".*",
"methodFilter": "read",
"valueExpression": "${params}"
},
{
"deviceNameFilter": ".*",
"methodFilter": "write",
"valueExpression": "${params}"
}
]
}

Top-level connection parameters for the FTP server.

ParameterDefaultDescription
hostlocalhostFTP server hostname or IP address
port21FTP server port
TLSSupporttrueVerify that TLS is available on the server

Configures how the connector authenticates with the FTP server.

Username and password authentication.

ParameterDefaultDescription
typebasicAuthorization type
usernameUsername
passwordPassword
"security": {
"type": "basic",
"username": "admin",
"password": "admin"
}

An array of path configurations. Each entry tells the connector which files to read, how often, and how to map the file contents to ThingsBoard device attributes and telemetry.

ParameterDescription
pathPath to the file(s) on the FTP server. Supports * wildcards
devicePatternNameExpression to build the ThingsBoard device name
devicePatternTypeExpression to determine the device type
delimiterCharacter used to split values within a file line
readModeFULL — read the entire file each poll; PARTIAL — read only new lines since the last poll
maxFileSizeMaximum file size in MB to read; larger files are skipped
pollPeriodHow often to poll the path, in seconds
txtFileDataViewTABLE — first line is a header; SLICED — no header, values extracted by index. Only applies to .txt files
withSortingFilesWhether to sort matched files before processing
attributesMappings from file values to ThingsBoard device attributes
timeseriesMappings from file values to ThingsBoard time-series telemetry

Path wildcard examples — for files in an FTP directory tree:

PathMatches
data/log.txtOne specific file
data/*/log.txtlog.txt in any immediate subdirectory of data/
data/*/_log.txtFiles ending in _log.txt in any immediate subdirectory of data/
data/*.*All files with supported extensions in data/

The first line is treated as a header. Key names and value expressions reference column header names.

"paths": [
{
"devicePatternName": "${temp}",
"devicePatternType": "Device",
"delimiter": ",",
"path": "fol/*.*",
"readMode": "FULL",
"maxFileSize": 5,
"pollPeriod": 60,
"txtFileDataView": "TABLE",
"withSortingFiles": true,
"attributes": [
{ "type": "int", "key": "key", "value": "${temp}" }
],
"timeseries": [
{ "type": "int", "key": "${hum}", "value": "${temp}" },
{ "type": "int", "key": "temp", "value": "${hum}" }
]
}
]

Expected file structure:

temp,hum
1,2
23,34

Use a custom converter when the file format is not natively supported (e.g. CSV without headers, or CSV with fixed column positions).

{
"converter": {
"type": "custom",
"extension": "CustomFTPtUplinkConverter",
"extension-config": {
"devicePatternName": 0,
"devicePatternType": 1,
"attributes": [
{ "key": "meterAddress", "column": 0, "type": "string" }
],
"timeseries": [
{ "key": "meterReading", "column": 2, "type": "double" },
{ "key": "batteryAlert", "column": 3, "type": "int" }
]
}
}
}
ParameterDescription
typeMust be custom
extensionName of the Python class implementing the custom converter
extension-config.devicePatternNameZero-based column index for the device name
extension-config.devicePatternTypeZero-based column index (or literal) for the device type
extension-config.attributes[].keyThingsBoard attribute key name
extension-config.attributes[].columnZero-based column index to read the attribute value from
extension-config.attributes[].typeValue type: string, int, or double
extension-config.timeseries[].keyThingsBoard telemetry key name
extension-config.timeseries[].columnZero-based column index to read the telemetry value from
extension-config.timeseries[].typeValue type: string, int, or double

Optional. Writes ThingsBoard shared attribute updates to files on the FTP server.

ParameterDefaultDescription
pathPath to the target file on the FTP server. Supports ${attributeKey} and ${attributeValue} expressions
deviceNameFilter.*Regex filter to match device names
writingModeOVERRIDE — overwrite the file; WRITE — append to the end of the file
valueExpressionExpression used to build the content written to the file
"attributeUpdates": [
{
"path": "fol/${attributeKey}/${attributeValue}.txt",
"deviceNameFilter": ".*",
"writingMode": "OVERRIDE",
"valueExpression": ",,,,${attributeKey},,,${attributeValue}"
}
]

Optional. Maps ThingsBoard RPC method calls to read or write operations on FTP server files.

ParameterDefaultDescription
deviceNameFilter.*Regex filter to match device names
methodFilterread — read from a file; write — write to a file
valueExpressionExpression used to build the content to write (ignored for read operations)
"serverSideRpc": [
{
"deviceNameFilter": ".*",
"methodFilter": "read",
"valueExpression": "${params}"
},
{
"deviceNameFilter": ".*",
"methodFilter": "write",
"valueExpression": "${params}"
}
]

Suppose you want to read data from the file on connected FTP server. Go to enabled FTP connector RPC page and fill in fields with the following configuration and click on “Send” button. After that, response will be shown in the “Response” field:

Suppose you want to write some data to the file on connected FTP server. Go to enabled FTP connector RPC page and fill in fields with the following configuration and click on “Send” button. After that, response will be shown in the “Response” field: