Skip to main content

snippets_js

Integration

New integration from credential
const ftpClient = yepcode.integration.ftp('credential-slug');
New integration from plain authentication data (username and password)
const Client = require('ftp');
const ftpClient = new Client();
ftpClient.connect({
host: 'hostname',
user: 'user',
password: 'password'
})

Directory Listing

Directory listing

ftpClient.on('ready', function() {
ftpClient.list(function(err, list) {
if (err) throw err;
console.dir(list);
ftpClient.end();
});
});

Retrieve a File

Retrieve a file

ftpClient.on('ready', function() {
ftpClient.get('readme.txt', function(err, stream) {
if (err) throw err;
stream.once('close', function() { ftpClient.end(); });
stream.pipe(fs.createWriteStream('foo.local-copy.txt'));
});
});

Upload Data

Upload data from stream to remote server
const Stream = require('stream');
const readableStream = new Stream.Readable({
// Create your readable stream
read() {}
});

ftpClient.on('ready', function() {
ftpClient.put(readableStream, 'remoteDirPath', function(err) {
if (err) throw err;
ftpClient.end();
});
});

Delete a File

Delete a file on the remote server
ftpClient.on('ready', function() {
ftpClient.delete('remoteDirPath', function(err) {
if (err) throw err;
ftpClient.end();
});
});