# SftpFile

> Sftp file source connector

### Key Features[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#key-features) <a href="#key-features" id="key-features"></a>

* [x] &#x20;batch
* [ ] &#x20;stream
* [ ] &#x20;exactly-once
* [x] &#x20;column projection
* [x] &#x20;parallelism
* [ ] &#x20;support user-defined split
* [x] &#x20;file format type
  * [x] &#x20;text
  * [x] &#x20;csv
  * [x] &#x20;json
  * [x] &#x20;excel
  * [x] &#x20;xml
  * [x] &#x20;binary

### Description[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#description) <a href="#description" id="description"></a>

Read data from sftp file server.

**tip**

We made some trade-offs in order to support more file types, so we used the HDFS protocol for internal access to Sftp and this connector need some hadoop dependencies. It only supports hadoop version **2.9.X+**.

### Data Type Mapping[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#data-type-mapping) <a href="#data-type-mapping" id="data-type-mapping"></a>

The File does not have a specific type list, and we can indicate which Nexus data type the corresponding data needs to be converted to by specifying the Schema in the config.

| Nexus Data type |
| --------------- |
| STRING          |
| SHORT           |
| INT             |
| BIGINT          |
| BOOLEAN         |
| DOUBLE          |
| DECIMAL         |
| FLOAT           |
| DATE            |
| TIME            |
| TIMESTAMP       |
| BYTES           |
| ARRAY           |
| MAP             |

### Source Options[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#source-options) <a href="#source-options" id="source-options"></a>

| Name                         | Type    | Required | default value       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ---------------------------- | ------- | -------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| host                         | String  | Yes      | -                   | The target sftp host is required                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| port                         | Int     | Yes      | -                   | The target sftp port is required                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| user                         | String  | Yes      | -                   | The target sftp username is required                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| password                     | String  | Yes      | -                   | The target sftp password is required                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| path                         | String  | Yes      | -                   | The source file path.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| file\_format\_type           | String  | Yes      | -                   | Please check #file\_format\_type below                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| file\_filter\_pattern        | String  | No       | -                   | Filter pattern, which used for filtering files.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| delimiter/field\_delimiter   | String  | No       | \001                | <p><strong>delimiter</strong> parameter will deprecate after version 2.3.5, please use <strong>field\_delimiter</strong> instead.<br>Field delimiter, used to tell connector how to slice and dice fields when reading text files.<br>Default <code>\001</code>, the same as hive's default delimiter</p>                                                                                                                                                                                                                                       |
| parse\_partition\_from\_path | Boolean | No       | true                | <p>Control whether parse the partition keys and values from file path<br>For example if you read a file from path <code>oss\://hadoop-cluster/tmp/nexus/parquet/name=tyrantlucifer/age=26</code><br>Every record data from file will be added these two fields:<br>name age<br>tyrantlucifer 26<br>Tips: <strong>Do not define partition fields in schema option</strong></p>                                                                                                                                                                   |
| date\_format                 | String  | No       | yyyy-MM-dd          | <p>Date type format, used to tell connector how to convert string to date, supported as the following formats:<br><code>yyyy-MM-dd</code> <code>yyyy.MM.dd</code> <code>yyyy/MM/dd</code><br>default <code>yyyy-MM-dd</code></p>                                                                                                                                                                                                                                                                                                                |
| datetime\_format             | String  | No       | yyyy-MM-dd HH:mm:ss | <p>Datetime type format, used to tell connector how to convert string to datetime, supported as the following formats:<br><code>yyyy-MM-dd HH:mm:ss</code> <code>yyyy.MM.dd HH:mm:ss</code> <code>yyyy/MM/dd HH:mm:ss</code> <code>yyyyMMddHHmmss</code><br>default <code>yyyy-MM-dd HH:mm:ss</code></p>                                                                                                                                                                                                                                        |
| time\_format                 | String  | No       | HH:mm:ss            | <p>Time type format, used to tell connector how to convert string to time, supported as the following formats:<br><code>HH:mm:ss</code> <code>HH:mm:ss.SSS</code><br>default <code>HH:mm:ss</code></p>                                                                                                                                                                                                                                                                                                                                          |
| skip\_header\_row\_number    | Long    | No       | 0                   | <p>Skip the first few lines, but only for the txt and csv.<br>For example, set like following:<br><code>skip\_header\_row\_number = 2</code><br>then Nexus will skip the first 2 lines from source files</p>                                                                                                                                                                                                                                                                                                                                    |
| read\_columns                | list    | no       | -                   | The read column list of the data source, user can use it to implement field projection.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| sheet\_name                  | String  | No       | -                   | Reader the sheet of the workbook,Only used when file\_format is excel.                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| xml\_row\_tag                | string  | no       | -                   | Specifies the tag name of the data rows within the XML file, only used when file\_format is xml.                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| xml\_use\_attr\_format       | boolean | no       | -                   | Specifies whether to process data using the tag attribute format, only used when file\_format is xml.                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| schema                       | Config  | No       | -                   | Please check #schema below                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| compress\_codec              | String  | No       | None                | <p>The compress codec of files and the details that supported as the following shown:<br>- txt: <code>lzo</code> <code>None</code><br>- json: <code>lzo</code> <code>None</code><br>- csv: <code>lzo</code> <code>None</code><br>- orc: <code>lzo</code> <code>snappy</code> <code>lz4</code> <code>zlib</code> <code>None</code><br>- parquet: <code>lzo</code> <code>snappy</code> <code>lz4</code> <code>gzip</code> <code>brotli</code> <code>zstd</code> <code>None</code><br>Tips: excel type does Not support any compression format</p> |
| encoding                     | string  | no       | UTF-8               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| common-options               |         | No       | -                   | Source plugin common parameters, please refer to [Source Common Options](/data-integration-with-nexus/nexus-elements/connectors/source/source-common-options.md)[on Options](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/common-options) for details.                                                                                                                                                                                                                                                                           |

#### file\_format\_type \[string][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#file_format_type-string) <a href="#file_format_type-string" id="file_format_type-string"></a>

File type, supported as the following file types: `text` `csv` `parquet` `orc` `json` `excel` `xml` `binary` If you assign file type to `json`, you should also assign schema option to tell connector how to parse data to the row you want. For example: upstream data is the following:

```
{"code":  200, "data":  "get success", "success":  true}
```

You can also save multiple pieces of data in one file and split them by newline:

```
{"code":  200, "data":  "get success", "success":  true}
{"code":  300, "data":  "get failed", "success":  false}
```

you should assign schema as the following:

```
schema {
    fields {
        code = int
        data = string
        success = boolean
    }
}
```

connector will generate data as the following: | code | data | success | |------|-------------|---------| | 200 | get success | true | If you assign file type to `parquet` `orc`, schema option not required, connector can find the schema of upstream data automatically. If you assign file type to `text` `csv`, you can choose to specify the schema information or not. For example, upstream data is the following:

```
tyrantlucifer#26#male
```

If you do not assign data schema connector will treat the upstream data as the following: | content | |-----------------------| | tyrantlucifer#26#male | If you assign data schema, you should also assign the option `field_delimiter` too except CSV file type you should assign schema and delimiter as the following:

```
field_delimiter = "#"
schema {
    fields {
        name = string
        age = int
        gender = string 
    }
}
```

connector will generate data as the following: | name | age | gender | |---------------|-----|--------| | tyrantlucifer | 26 | male |

If you assign file type to `binary`, Nexus can synchronize files in any format, such as compressed packages, pictures, etc. In short, any files can be synchronized to the target place. Under this requirement, you need to ensure that the source and sink use `binary` format for file synchronization at the same time.

#### compress\_codec \[string][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#compress_codec-string) <a href="#compress_codec-string" id="compress_codec-string"></a>

The compress codec of files and the details that supported as the following shown:

* txt: `lzo` `none`
* json: `lzo` `none`
* csv: `lzo` `none`
* orc/parquet:\
  automatically recognizes the compression type, no additional settings required.

#### encoding \[string][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#encoding-string) <a href="#encoding-string" id="encoding-string"></a>

Only used when file\_format\_type is json,text,csv,xml. The encoding of the file to read. This param will be parsed by `Charset.forName(encoding)`.

#### schema \[config][​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#schema-config) <a href="#schema-config" id="schema-config"></a>

**fields \[Config]**[**​**](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#fields-config)

The schema of upstream data.

### How to Create a Sftp Data Synchronization Jobs[​](https://seatunnel.apache.org/docs/2.3.7/connector-v2/source/SftpFile#how-to-create-a-sftp-data-synchronization-jobs) <a href="#how-to-create-a-sftp-data-synchronization-jobs" id="how-to-create-a-sftp-data-synchronization-jobs"></a>

The following example demonstrates how to create a data synchronization job that reads data from sftp and prints it on the local client:

```
# Set the basic configuration of the task to be performed
env {
  parallelism = 1
  job.mode = "BATCH"
}

# Create a source to connect to sftp
source {
  SftpFile {
    host = "sftp"
    port = 22
    user = "nexus"
    password = "pass"
    path = "tmp/nexus/read/json"
    file_format_type = "json"
    result_table_name = "sftp"
    schema = {
      fields {
        c_map = "map<string, string>"
        c_array = "array<int>"
        c_string = string
        c_boolean = boolean
        c_tinyint = tinyint
        c_smallint = smallint
        c_int = int
        c_bigint = bigint
        c_float = float
        c_double = double
        c_bytes = bytes
        c_date = date
        c_decimal = "decimal(38, 18)"
        c_timestamp = timestamp
        c_row = {
          C_MAP = "map<string, string>"
          C_ARRAY = "array<int>"
          C_STRING = string
          C_BOOLEAN = boolean
          C_TINYINT = tinyint
          C_SMALLINT = smallint
          C_INT = int
          C_BIGINT = bigint
          C_FLOAT = float
          C_DOUBLE = double
          C_BYTES = bytes
          C_DATE = date
          C_DECIMAL = "decimal(38, 18)"
          C_TIMESTAMP = timestamp
        }
      }
    }
  }
}

# Console printing of the read sftp data
sink {
  Console {
    parallelism = 1
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.selfuel.digital/data-integration-with-nexus/nexus-elements/connectors/source/sftpfile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
