Skip to main content

sftp@1.0.2

Functions

getCSV(filePath, [parsingOptions])
getJSON(filePath, encoding)
list(dirPath, filter, [callback])
normalizeCSVarray(options, callback)
putCSV(localFilePath, remoteFilePath, parsingOptions)

The following functions are exported from the common adaptor:

alterState()
chunk()
dataPath()
dataValue()
each()
field()
fields()
fn()
http()
lastReferenceValue()
merge()
parseCsv()
sourceValue()

getCSV

getCSV(filePath, [parsingOptions]) ⇒ Operation

Get a CSV and return a JSON array of strings for each item separated by the delimiter

ParamTypeDescription
filePathstringPath to resource
[parsingOptions]ObjectOptional. 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

ParamTypeDescription
filePathstringPath to resource
encodingstringCharacter encoding for the json

Example

getJSON(
'/path/To/File',
'utf8',
);

list

list(dirPath, filter, [callback]) ⇒ Operation

List files present in a directory

ParamTypeDescription
dirPathstringPath to remote directory
filterfunctiona filter function used to select return entries
[callback]functionOptional 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

ParamTypeDescription
optionsoptionsOptions passed to csvtojson parser
callbackcallbackOptions 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

ParamTypeDescription
localFilePathstringData source for data to copy to the remote server.
remoteFilePathstringPath to the remote file to be created on the server.
parsingOptionsobjectOptions 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 }
);