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)

getCSV​

getCSV(filePath, [parsingOptions]) β‡’ Operation Get a CSV and return a JSON array of strings for each item separated by the delimiter

Kind: global function
Access: public

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

Kind: global function
Access: public

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

Kind: global function
Access: public

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

Kind: global function
Access: public

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

Kind: global function
Access: public

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 }
);