sftp@2.0.5
- getCSV(filePath, [parsingOptions])
- getJSON(filePath, encoding)
- list(dirPath, filter, [callback])
- normalizeCSVarray(options, callback)
- putCSV(localFilePath, remoteFilePath, parsingOptions)
This adaptor exports the following from common:
- alterState()
- chunk()
- dataPath()
- dataValue()
- each()
- field()
- fields()
- fn()
- fnIf()
- http
- lastReferenceValue()
- merge()
- parseCsv()
- sourceValue()
Functions
getCSV
getCSV(filePath, [parsingOptions]) ⇒ Operation
Get a CSV and return a JSON array of strings for each item separated by the delimiter
Param | Type | Description |
---|---|---|
filePath | string | Path to resource |
[parsingOptions] | Object | Optional. parsingOptions Parsing options which can be passed to convert csv to json See more on csvtojson docs |
Example
getCSV(
'/some/path/to_file.csv',
{delimiter: ";", flatKeys: true }
);
getJSON
getJSON(filePath, encoding) ⇒ Operation
Fetch a json file from an FTP server
Param | Type | Description |
---|---|---|
filePath | string | Path to resource |
encoding | string | Character encoding for the json |
Example
getJSON(
'/path/To/File',
'utf8',
);
list
list(dirPath, filter, [callback]) ⇒ Operation
List files present in a directory
Param | Type | Description |
---|---|---|
dirPath | string | Path to remote directory |
filter | function | a filter function used to select return entries |
[callback] | function | Optional callback to handle the response |
Example: basic files listing
list('/some/path/')
Example: list files with filters
list('/some/path/', file=> {
return /foo.\.txt/.test(file.name);
})
Example: list files with filters and use callback
list(
"/some/path/",
(file) => /foo.\.txt/.test(file.name),
(state) => {
const latestFile = state.data.filter(
(file) => file.modifyTime <= new Date()
);
return { ...state, latestFile };
}
);
normalizeCSVarray
normalizeCSVarray(options, callback) ⇒ Operation
Convert JSON array of strings into a normalized object
Param | Type | Description |
---|---|---|
options | options | Options passed to csvtojson parser |
callback | callback | Options passed to csvtojson parser |
Example
normalizeCSVarray({ delimiter: ';', noheader: true });
putCSV
putCSV(localFilePath, remoteFilePath, parsingOptions) ⇒ Operation
Convert JSON to CSV and upload to an FTP server
Param | Type | Description |
---|---|---|
localFilePath | string | Data source for data to copy to the remote server. |
remoteFilePath | string | Path to the remote file to be created on the server. |
parsingOptions | object | Options which can be passed to adjust the read and write stream used in sending the data to the remote server |
Example
putCSV(
'/some/path/to_local_file.csv',
'/some/path/to_remove_file.csv',
{ delimiter: ';', noheader: true }
);