SFTP
SSH File Transfer Protocol (SFTP) gives you a secure file transfer capability. Wrapped around SSH2 which provides a high level convenience abstraction as well as a Promise based API.

Network Connection needs
This integration needs network access to the server where the service is running.
See the Network access page for details about how to achieve that.
This integration works with SSH File Transfer Protocol (SFTP). If you need to use other FTP protocol, take a lot to our FTP integration.
Credential configuration
To configure this credential you need the host
, port
and username
to connect to FTP server.
Then you'll need a password
or the private key
depending on how you want to connect.
Optionally you can set any of the extra config params you can see here.
Here you have an example of a filled credential configuration form in YepCode:

SFTP snippets available in editor
The title is the triggering text for YepCode to autocomplete the script
Integration
const sftpClient = await yepcode.integration.sftp('credential-slug');
const Client = require('ssh2-sftp-client');
const options = {
host: 'hostname',
port: portNumber,
username: 'username',
password: 'password',
};
const sftpClient = new Client();
await sftpClient.connect(options);
const Client = require('ssh2-sftp-client');
const options = {
host: 'hostname',
port: portNumber,
username: 'username',
privateKey: 'privateKey',
};
const sftpClient = new Client();
await sftpClient.connect(options);
Directory listing
sftpClient.list('remoteDirPath')
.then((data) => {
console.log(data);
})
.catch(console.error)
.finally(() => sftpClient.end());
Check if directory exists
sftpClient.exists('remoteDirPath')
.then((exists) => {
console.log(exists);
})
.catch(console.error)
.finally(() => sftpClient.end());
Object stats
sftpClient.stat('remoteDirPath')
.then((data) => {
console.log(data);
})
.catch(console.error)
.finally(() => sftpClient.end());
Retrieve a file
const Stream = require('stream');
const echoStream = new Stream.Writable({
write: function (chunk, encoding, next) {
console.debug('echoStream:', chunk.toString());
next();
}
});
sftpClient.get('remoteDirPath', echoStream)
.catch(console.error)
.finally(() => sftpClient.end());
Upload data
const Stream = require('stream');
const readableStream = new Stream.Readable({
read() {}
});
sftpClient.put(readableStream, 'remoteDirPath')
.catch(console.error)
.finally(() => sftpClient.end());
Append input data
sftpClient.append(Buffer.from('Hello world'), 'remoteFilePath')
.catch(console.error)
.finally(() => sftpClient.end());
Delete a file
sftpClient.delete('remoteFilePath')
.catch(console.error)
.finally(() => sftpClient.end());
Create a new directory
sftpClient.mkdir('remoteFilePath', true)
.catch(console.error)
.finally(() => sftpClient.end());
Rename a file or directory
const from = '/remote/path/to/old.txt';
const to = '/remote/path/to/new.txt';
sftpClient.rename(from, to)
.catch(console.error)
.finally(() => sftpClient.end());
POSIX rename
const from = '/remote/path/to/old.txt';
const to = '/remote/path/to/new.txt';
sftpClient.posixRename(from, to)
.catch(console.error)
.finally(() => sftpClient.end());
Current directory
sftpClient.cwd()
.then((directory) => {
console.log(`Remote working directory is ${directory}`);
})
.catch(console.error)
.finally(() => sftpClient.end());