SFTP Sink Connector for Confluent Cloud

You can use the managed SFTP Sink connector for Confluent Cloud to export data from Apache Kafka® topics to files in an SFTP directory.

The SFTP Sink connector periodically polls data from Kafka and writes this data to SFTP files. A time-based partitioner is used to split the data of every Kafka partition into chunks. Each chunk of data is represented as a file. The file name encodes the topic, the Kafka partition, and the start offset of this data chunk. The size of each data chunk is determined by the number of records written and by schema compatibility.

Features

The SFTP Sink connector supports the following features:

  • Exactly once delivery: Records that are exported using a deterministic partitioner are delivered with exactly-once semantics.
  • Partitioner: The connector supports the TimeBasedPartitioner class based on the Kafka class TimeStamp. Time-based partitioning options are daily or hourly.
  • Supports multiple tasks: The connector supports running one or more tasks. More tasks may improve performance.
  • Supported data formats: The connector supports Avro, JSON Schema (JSON-SR), Protobuf, JSON (schemaless), and Bytes input data formats. The connector supports Avro and JSON output formats. Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON Schema, or Protobuf).

For configuration property values and descriptions, see Configuration Properties.

For additional information, refer to Cloud connector limitations.

Quick Start

Use this quick start to get up and running with the Confluent Cloud SFTP Sink connector. The quick start provides the basics of selecting the connector and configuring it to stream events to an SFTP directory.

Prerequisites
  • Authorized access to a Confluent Cloud cluster on Amazon Web Services (AWS), Microsoft Azure (Azure), or Google Cloud Platform (GCP).
  • The Confluent CLI installed and configured for the cluster. See Install the Confluent CLI.
  • Access to an SFTP host.
  • Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).
  • At least one source Kafka topic must exist in your Confluent Cloud cluster before creating the sink connector.

Using the Confluent Cloud Console

Step 1: Launch your Confluent Cloud cluster.

See the Quick Start for Apache Kafka using Confluent Cloud for installation instructions.

Step 2: Add a connector.

In the left navigation menu, click Data integration, and then click Connectors. If you already have connectors in your cluster, click + Add connector.

Step 3: Select your connector.

Click the SFTP Sink connector icon.

SFTP Sink Connector Icon

Step 4: Set up the connection.

Note

  • Make sure you have all your prerequisites completed.
  • An asterisk ( * ) designates a required entry.
  1. Select one or more topics.

  2. Enter a connector Name.

  3. Select an Input Kafka record value format (data coming from the Kafka topic): AVRO, PROTOBUF, JSON_SR (JSON Schema), JSON (schemaless), or BYTES. A valid schema must be available in Schema Registry to use a schema-based message format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).

  4. Select the way you want to provide Kafka Cluster credentials. You can either select a service account resource ID or you can enter an API key and secret (or generate these in the Cloud Console).

  5. Enter the SFTP Details:

    • SFTP Host: Enter the host address for the SFTP server. For example 192.168.1.231.
    • SFTP Port: Enter the SFTP host port to use. If no port number is entered, this defaults to 22.
    • Username: Enter the user name that the connector will use to connect to the host.
    • Password: Enter the password for the user name entered. A password is not required if a PEM file is used for key based authentication to the host.
    • PEM File: If using TLS, upload the PEM file that contains the private key for the SFTP user.
    • TLS passphrase: If the private key is encrypted, enter the passphrase to decrypt the private key.
    • SFTP Working Directory: Enter a path to the home directory on the SFTP server. If no path is entered, this defaults to /home.
  6. Select an Output Kafka record value format: AVRO or JSON (schemaless).

  7. Enter the SFTP host data organization details.

    The Path format, Topic directory, and Time interval properties can be used to build a directory structure for stored data. For example: You set Time interval to HOURLY, Topics directory to json_logs/hourly, and Path format to 'dt'=YYYY-MM-dd/'hr'=HH. The result is the directory structure: filesystem://store-name/json_logs/hourly/<Topic-Name>/dt=2020-02-06/hr=09/<files>.

    • Enter a Topic directory (Optional): This is a top-level directory name to use for stored data. Defaults to topics if not used.
    • Enter a Path format (Optional): This configures the time-based partitioning path created in the file system. The property converts the UNIX timestamp to a date format string. If not used, this property defaults to 'year'=YYYY/'month'=MM/'day'=dd/'hour'=HH if an Hourly Time interval was selected or 'year'=YYYY/'month'=MM/'day'=dd if a Daily Time interval was selected.
    • Select the Time interval that sets how you want your messages grouped in the file system. For example, if you select Hourly, messages are grouped into folders for each hour data is streamed to the file system.
    • See Configuration Properties for details about the two optional rotation interval properties.
    • Enter the Flush size: This value defaults to 1000. The default value can be raised.
    • Enter the Timestamp field name: The record field used for the timestamp, which is used with the time-base partitioner. If not used, this defaults to the timestamp when the Kafka record was produced or stored by the Kafka broker.
    • Timezone: Use a valid timezone. Defaults to UTC if not used. - Locale: Select a locale. Defaults to en.
    • Compression Type (Optional): Select a compression type for files. Use deflate, snappy, or bzip2 for AVRO output. Use gzip for JSON output.
  8. Enter the number of tasks to use with the connector. More tasks may improve performance.

  9. Transforms and Predicates: See the Single Message Transforms (SMT) documentation for details.

See Configuration Properties for configuration property values and descriptions.

Step 5: Launch the connector.

Verify the connection details and click Launch.

Step 6: Check the connector status.

The status for the connector should go from Provisioning to Running.

Step 7: Check for files.

Verify that records are being produced on the SFTP host.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

Tip

When you launch a connector, a Dead Letter Queue topic is automatically created. See Dead Letter Queue for details.

Using the Confluent CLI

To set up and run the connector using the Confluent CLI, complete the following steps.

Note

Make sure you have all your prerequisites completed.

Step 1: List the available connectors.

Enter the following command to list available connectors:

confluent connect plugin list

Step 2: Show the required connector configuration properties.

Enter the following command to show the required connector properties:

confluent connect plugin describe <connector-catalog-name>

For example:

confluent connect plugin describe SftpSink

Example output:

Following are the required configs:
connector.class: SftpSink
topics
input.data.format
name
kafka.api.key
kafka.api.secret
sftp.host
sftp.username
output.data.format
time.interval
rotate.schedule.interval.ms
rotate.interval.ms
tasks.max

Step 3: Create the connector configuration file.

Create a JSON file that contains the connector configuration properties. The following example shows the required connector properties.

{
  "connector.class": "SftpSink",
  "topics": "orders",
  "input.data.format": "JSON",
  "name": "SftpSinkConnector_0",
  "kafka.api.key": "****************",
  "kafka.api.secret": "*********************************",
  "sftp.host": "192.168.1.231",
  "sftp.username": "connect-user",
  "sftp.password:": "****************",
  "output.data.format": "JSON",
  "time.interval": "HOURLY",
  "rotate.schedule.interval.ms": "",
  "rotate.interval.ms": "",
  "tasks.max": "1",
}

Note the following property definitions:

  • "connector.class": Identifies the connector plugin name.
  • "topics": Enter the topic name or a comma-separated list of topic names.
  • "input.data.format": Sets (data coming from the Kafka topic): AVRO, PROTOBUF, JSON_SR (JSON Schema), JSON (schemaless), or BYTES. A valid schema must be available in Schema Registry to use a schema-based message format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).
  • "name": Sets a name for your new connector.
  • "kafka.api.key" and "kafka.api.secret": These credentials are either the cluster API key and secret or the service account API key and secret.
  • "sftp.host": Enter the host address for the SFTP server. For example 192.168.1.231. Note that the port defaults to 22. To change this, add the property "sftp.port".
  • "sftp.username": Enter the user name that the connector will use to connect to the host.
  • "output.data.format": Enter AVRO or JSON (schemaless). A valid schema must be available in Schema Registry to use a schema-based message format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).
  • "time.interval": Sets how you want your messages grouped in the file system. Options are HOURLY or DAILY.
  • "rotate.schedule.interval.ms" and "rotate.interval.ms": See the Configuration Properties for the property descriptions.
  • "tasks.max": Enter the maximum number of tasks for the connector to use. More tasks may improve performance.

Note

The properties path.format, topics.dir, and time.interval properties can be used to build a directory structure for stored data. For example, you set time.interval to HOURLY, topics.dir to json_logs/hourly, and path.format` to ``'dt'=YYYY-MM-dd/'hr'=HH. The result is the directory structure: filesystem://store-name/json_logs/hourly/<Topic-Name>/dt=2020-02-06/hr=09/<files>. See the Configuration Properties for property values and definitions.

Single Message Transforms: See the Single Message Transforms (SMT) documentation for details about adding SMTs using the CLI.

For configuration property values and descriptions, see Configuration Properties.

Step 3: Load the properties file and create the connector.

Enter the following command to load the configuration and start the connector:

confluent connect create --config <file-name>.json

For example:

confluent connect create --config sftp-sink-config.json

Example output:

Created connector SftpSinkConnector_0 lcc-do6vzd

Step 4: Check the connector status.

Enter the following command to check the connector status:

confluent connect list

Example output:

ID           |             Name              | Status  | Type | Trace
+------------+-------------------------------+---------+------+-------+
lcc-do6vzd   | SftpSinkConnector_0           | RUNNING | sink |       |

Step 5: Check for files.

Verify that records are being produced on the SFTP host.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

Tip

When you launch a connector, a Dead Letter Queue topic is automatically created. See Dead Letter Queue for details.

Configuration Properties

The following connector configuration properties can be used with the SFTP Sink connector for Confluent Cloud.

sftp.host

SFTP host server to connect to.

  • Type: String
  • Importance: High
sftp.port

Port number of SFTP server. Defaults to port 22.

  • Type: Int
  • Default: 22
  • Importance: Medium
sftp.username

User name for the SFTP server.

  • Type: String
  • Importance: High
sftp.password

Password for the SFTP server.

  • Type: String
  • Importance: High
tls.pemfile

PEM file to be used for authentication via TLS. To use this property, you must first encode the binary PEM file in base64, take the encoded string, add the data:text/plain;base64 prefix, and then specify the entire string as the property entry. For example: "tls.pemfile" : "data:text/plain;base64,/u3+7QAAAAIAAAACAAAAAQAGY2xpZ...==".

  • Type: Password
  • Importance: High
tls.passphrase

Passphrase that is used to decrypt the private key if the given private key is encrypted.

  • Type: Password
  • Default: [hidden]
  • Importance: Low
sftp.working.dir

Home directory on the SFTP server. This is the top-most directory on the SFTP host that contains all the files from the connector. Defaults to /home.

  • Type: String
  • Default: /home
  • Importance: High
topics.dir

Directory where ingested data is stored. Defaults to topics.

  • Type: String
  • Default: topics
  • Importance: High
time.interval

Partitioning interval of data, according to the time ingested to storage.

  • Type: String
  • Valid Values: [HOURLY, DAILY]
  • Importance: High
flush.size

Number of records written to store before invoking file commits. Defaults to 1000 records.

  • Type: Int
  • Default: 1000
  • Importance: High
rotate.interval.ms

The time interval in milliseconds to invoke file commits. This configuration is useful when data ingestion rate is low and the connector didn’t write enough messages to commit files. The default value -1 means that this property is disabled.

  • Type: Long
  • Default: -1
  • Importance: High
rotate.schedule.interval.ms

The time interval in milliseconds to periodically invoke file commits. Time of commit will be adjusted to 00:00 for the selected time zone. The commit will be performed at scheduled time, all other factors considered (i.e., flush.size). This configuration is useful when you have to commit your data based on current server time, like at the beginning of every hour. You must have the partitioner parameter timezone configured (defaults to an empty string) when using this configuration property, otherwise the connector fails with an exception. The default value -1 means that this property is disabled.

  • Type: Long
  • Default: -1
  • Importance: Medium
timestamp.field

The record field used for the timestamp, which is used with the time-base partitioner. If not used, this defaults to the timestamp when the Kafka record was produced or stored by the Kafka broker.

  • Type: String
  • Default: timestamp
  • Importance: Medium
timezone

The time zone to use for time-based partitioning. Used to format and compute dates and times. All time zone IDs must be specified in the long format, such as America/Los_Angeles, America/New_York, and Europe/Paris, or UTC. Alternatively a locale independent, fixed offset, time zone can be specified in form [+-]hh:mm.

  • Type: String
  • Default: “”
  • Importance: Medium
locale

The locale to use for time-based partitioning.. Used to format dates and times. For example, use en-US for US English, en-GB for UK English, or fr-FR for French (in France). Defaults to en.

  • Type: String
  • Default: en
  • Importance: Medium
sftp.compression.type

The compression type for files. Use deflate, snappy, or bzip2 for AVRO output. Use gzip for JSON output.

  • Type: String
  • Importance: Low

Next Steps

See also

For an example that shows fully-managed Confluent Cloud connectors in action with Confluent Cloud ksqlDB, see the Cloud ETL Demo. This example also shows how to use Confluent CLI to manage your resources in Confluent Cloud.

../_images/topology.png