Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@openfn/language-sftp
Advanced tools
Language Pack for building expressions and operations to work with SFTP servers.
View all the required and optional properties for state.configuration
in the
official
configuration-schema
definition.
alterState(state => {
return list('/path/To/Directory')(state).then(response => {
console.log(`There are ${response.data.length} files.`);
return response;
});
});
getCSV('path/to/file.csv', 'utf8', {
quote: 'off',
delimiter: ';',
noheader: true,
filter: {
type: 'startsWith',
key: 'field1',
value: 'JO',
},
});
A more complex example that breaks up the CSV file into multiple payloads for quicker processing.
fn(state => {
return list('/')(state).then(state => {
const targetNames = [
'exportContacts', //example fileName
];
console.log(`Fetching files: ${targetNames}`);
const files = state.data
.filter(file => file.name.split('.')[1] === 'csv')
.filter(file =>
targetNames.some(targetName =>
file.name.toLowerCase().includes(targetName)
)
);
if (files.length === 0) console.log('No new CSV files found.');
return { ...state, data: {}, files };
});
});
each(
'$.files[*]',
fn(state => {
const { configuration, data } = state;
return getCSV(`/${data.name}`)(state).then(async state => {
const headers = state.data
.shift()
.split(';')
.map(h => (h = h.replace(/"/g, '')));
function toObject(item) {
const values = item.split(';');
return Object.fromEntries(
headers.map((k, i) => {
return values[i]
? [k, values[i].replace(/"/g, '')]
: [k, values[i]];
})
);
}
let countInbox = 0;
//to post CSV data as individual Messages to OpenFn Inbox
const postToInbox = async data => {
countInbox++;
console.log(`Sending request ${countInbox} to inbox`);
await new Promise(resolve => setTimeout(resolve, 200));
await http.post({
url: configuration.openfnInboxUrl,
data: data,
maxContentLength: Infinity,
maxBodyLength: Infinity,
})(state);
};
//To split up into multiple, smaller payloads before send to OpenFn Inbox
const chunkSize = 500;
console.log(
state.data.length,
'rows will be sent in',
Math.ceil(state.data.length / chunkSize),
'requests of',
chunkSize,
'rows each.'
);
while (state.data.length > 0) {
console.log('data.length', state.data.length);
await postToInbox({
fileName: data.name,
fileType: data.name.split('-')[0],
uploadDate: new Date(data.modifyTime).toISOString(),
json: state.data.splice(0, chunkSize).map(toObject),
});
}
return { configuration, references: [], data: {} };
});
})
);
This function converts JSON to CSV and post to a server
putCSV('/some/path/to_file.csv', 'utf8', { delimiter: ';', noheader: true });
getJSON('path/to/file.json', 'utf8');
This adaptor exports http
from language-common
. Here, we outline the usage
in order to make custom requests to an endpoint. It returns a promise
alterState(state => {
return http
.post({ url: 'yourURL', data: { name: 'Mamadou' } })(state)
.then(response => {
// do something with response;
return response;
});
});
Clone the repo, run pnpm install
.
Run tests using pnpm run test
or pnpm run test:watch
Build the project using pnpm build
.
To build the docs for this repo, pnpm build docs
FAQs
An SFTP language package for use with Open Function
The npm package @openfn/language-sftp receives a total of 77 weekly downloads. As such, @openfn/language-sftp popularity was classified as not popular.
We found that @openfn/language-sftp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.