DataWorks provides FTP Reader and FTP Writer for you to read data from and write data to FTP data sources. This topic describes the capabilities of synchronizing data from or to FTP data sources.
Limits
FTP Reader connects to a remote FTP server, reads data from the server, and then converts the format of the data into a format that is readable to Data Integration. The files on the FTP server store only unstructured data. The following table lists the features that are supported and not supported by FTP Reader:
Supported | Not supported |
|
|
FTP Writer converts the data that is obtained from a reader to files and writes the files to an FTP server. The files on the FTP server store only unstructured data. The following table lists the features that are supported and not supported by FTP Writer:
Supported | Not supported |
|
|
Data type mappings
A remote FTP file does not distinguish between data types. The data types are defined by FTP Reader.
Data Integration data type | Data type in an FTP file |
LONG | LONG |
DOUBLE | DOUBLE |
STRING | STRING |
BOOLEAN | BOOLEAN |
DATE | DATE |
Develop a data synchronization task
For information about the entry point for and the procedure of configuring a data synchronization task, see the following sections. For information about the parameter settings, view the infotip of each parameter on the configuration tab of the task.
Add a data source
Before you configure a data synchronization task to synchronize data from or to a specific data source, you must add the data source to DataWorks. For more information, see Add and manage data sources.
Configure a batch synchronization task to synchronize data of a single table
For more information about the configuration procedure, see Configure a batch synchronization task by using the codeless UI and Configure a batch synchronization task by using the code editor.
For information about all parameters that are configured and the code that is run when you use the code editor to configure a batch synchronization task, see Appendix: Code and parameters.
Appendix: Code and parameters
Appendix: Configure a batch synchronization task by using the code editor
If you use the code editor to configure a batch synchronization task, you must configure parameters for the reader and writer of the related data source based on the format requirements in the code editor. For more information about the format requirements, see Configure a batch synchronization task by using the code editor. The following information describes the configuration details of parameters for the reader and writer in the code editor.
Code for FTP Reader
{
"type":"job",
"version":"2.0",// The version number.
"steps":[
{
"stepType":"ftp",// The plug-in name.
"parameter":{
"path":[],// The file path.
"nullFormat":"",// The string that represents a null pointer.
"compress":"",// The format in which files are compressed.
"datasource":"",// The name of the data source.
"column":[// The names of the columns.
{
"index":0,// The ID of the column.
"type":""// The data type.
}
],
"skipHeader":"",// Specifies whether to skip the headers in the file if the file has headers.
"fieldDelimiter":",",// The column delimiter.
"encoding":"UTF-8",// The encoding format.
"fileFormat":"csv"// The format of the file.
},
"name":"Reader",
"category":"reader"
},
{
"stepType":"stream",
"parameter":{},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{
"record":"0"// The maximum number of dirty data records allowed.
},
"speed":{
"throttle":true,// Specifies whether to enable throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"concurrent":1 // The maximum number of parallel threads.
"mbps":"12",// The maximum transmission rate. Unit: MB/s.
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Parameters in code for FTP Reader
Parameter | Description | Required | Default value |
datasource | The name of the data source. It must be the same as the name of the added data source. You can add data sources by using the code editor. | Yes | No default value |
path | The path on the FTP server from which you want to read data. The path must be a full path that contains the path of the directory that stores the desired file and contains the file name with a suffix. You can specify multiple paths.
Note
| Yes | No default value |
column | The columns from which you want to read data. The type parameter specifies the data type of a column. The index parameter specifies the ID of a column in the source table, starting from 0. The value parameter specifies the column value if the column is a constant column. By default, FTP Reader reads all data as strings. In this case, set this parameter to
In the column parameter, you must configure the type parameter and configure one of the index and value parameters. | Yes | No default value |
fieldDelimiter | The column delimiter that is used in the file from which you want to read data. Note You must specify a column delimiter for FTP Reader. The default delimiter is commas (,). If you do not specify the column delimiter, the default column delimiter is used. | Yes | , |
skipHeader | Specifies whether to skip the headers in a CSV-like file if the file has headers. The skipHeader parameter is not supported for compressed files. The default value of this parameter is false, which indicates that FTP Reader does not skip the headers in CSV-like files. | No | false |
encoding | The encoding format of the files that you want to write to the FTP server. | No | utf-8 |
nullFormat | The string that represents a null pointer. No standard strings can represent a null pointer in TXT files. You can use this parameter to define a string that represents a null pointer. Examples:
| No | No default value |
markDoneFileName | The name of the file that is used to indicate that the synchronization task can start. Data Integration checks whether the file exists before data synchronization. If the file does not exist, Data Integration checks again later. Data Integration starts the synchronization task only after the file is detected. | No | No default value |
maxRetryTime | The maximum number of retries for the detection of the file if no file is detected. By default, a maximum of 60 retries are allowed. Data Integration detects the file every 1 minute. The whole process lasts for 60 minutes. | No | 60 |
csvReaderConfig | The configurations required to read CSV files. The parameter value must match the MAP type. You can use a CSV file reader to read data from CSV files. The CSV file reader supports multiple configurations. | No | No default value |
fileFormat | The format of the file. By default, FTP Reader reads data from CSV files. The data in CSV files must be logical two-dimensional tables. If you specify binary as the file format, data is converted into the binary format for replication and transmission. You need to configure this parameter only when you want to replicate the complete directory structure between storage systems such as FTP and Object Storage Service (OSS). | No | No default value |
Code for FTP Writer
{
"type":"job",
"version":"2.0",// The version number.
"steps":[
{
"stepType":"stream",
"parameter":{},
"name":"Reader",
"category":"reader"
},
{
"stepType":"ftp",// The plug-in name.
"parameter":{
"path":"",// The directory on the FTP server to which you want to write files.
"fileName":"",// The name prefix of the files that you want to write to the FTP server.
"nullFormat":"null",// The string that represents a null pointer.
"dateFormat":"yyyy-MM-dd HH:mm:ss",// The time format.
"datasource":"",// The name of the data source.
"writeMode":"",// The write mode.
"fieldDelimiter":",",// The column delimiter.
"encoding":"",// The encoding format.
"fileFormat":""// The format in which FTP Writer writes files.
},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{
"record":"0"// The maximum number of dirty data records allowed.
},
"speed":{
"throttle":true,// Specifies whether to enable throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true.
"concurrent":1, // The maximum number of parallel threads.
"mbps":"12"// The maximum transmission rate. Unit: MB/s.
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Parameters in code for FTP Writer
Parameter | Description | Required | Default value |
datasource | The name of the data source. It must be the same as the name of the added data source. You can add data sources by using the code editor. | Yes | No default value |
timeout | The timeout period of the connection to an FTP server. Unit: milliseconds. | No | 60,000 |
path | The directory on the FTP server to which you want to write files. FTP Writer uses parallel threads to write multiple files to the directory based on the parallelism setting. | Yes | No default value |
fileName | The name prefix of the files that you want to write to the FTP server. A random suffix is appended to file names to form the actual file names that is used by each thread. | Yes | No default value |
singleFileOutput | Specifies whether to add a random suffix to the names of the files that you want to write to the FTP server. The names of the files that FTP Writer writes to the FTP server are related to the value of the fileName parameter. If you do not need the random suffix, set the singleFileOutput parameter to true. In this case, FTP Writer writes the files to the FTP server by using the name prefix of the files. | No | false |
writeMode | The mode in which FTP Writer writes files. Valid values:
| Yes | No default value |
fieldDelimiter | The column delimiter that is used in the files that you want to write to the FTP server. The delimiter must be a single character. | Yes | No default value |
skipHeader | Specifies whether to skip the headers in a CSV-like file if the file has headers. By default, the headers are not skipped. The skipHeader parameter is unavailable for compressed files. | No | false |
compress | The compression format of the files that you want to write to the FTP server. Valid values: gzip and bzip2. | No | Not default value |
encoding | The encoding format of the files that you want to write to the FTP server. | No | utf-8 |
nullFormat | The string that represents a null pointer. No standard strings can represent a null pointer in text files. You can use this parameter to define which string represents a null pointer. For example, if you set | No | No default value |
dateFormat | The format in which the data of the DATE type is serialized in a file, such as "dateFormat":"yyyy-MM-dd". | No | No default value |
fileFormat | The format in which files are written to the FTP server. Valid values: CSV and TEXT. If a file is written as a CSV file, the file must follow CSV specifications. If the data in the file contains column delimiters, the column delimiters are escaped by double quotation marks ("). If a file is written as a TXT file, the data in the file is separated by column delimiters. In this case, the column delimiters are not escaped. | No | TEXT |
header | The table headers if files are written as TXT or CSV files, such as ["id","name","age"]. This indicates that the id, name, and age fields are written to a CSV file as the first row. | No | No default value |
markDoneFileName |
| No | No default value |