Using Stedi SFTP with the SDK
This example shows how to use the Stedi SFTP SDK. This is of use to JavaScript developers who want to generate SFTP credentials programmatically, but don't want to interact with the Stedi SFTP API directly.
Authentication
STEDI_API_KEY
. You can do that with the following command.export STEDI_API_KEY=replace.withYourOwnApiKey
Install the SDK
npm install --save @stedi/sdk-client-sftp
in your local
directory. Please note that to run the following examples you need to install node@16
or higher.Create an SFTP user
description
, homeDirectory
and passwordOptions
.description
helps you find the user account later if you need to.homeDirectory
determines which files and directory the user has access to. The user can access any file or directory under their home directory, but none outside it.passwordOptions
determines how the password is generated.length
determines the length of the password.
const stediSftpSdk = require("@stedi/sdk-client-sftp");
const apiKey = process.env.STEDI_API_KEY; // Fetch your API key from an environment variable.
// Create a new SFTP Client for the Stedi US region
const stediSftpClient = new stediSftpSdk.SftpClient({
region: "us",
apiKey: apiKey,
});
// Create an SFTP user for Alice
const createUserOutput = await stediSftpClient.send(
new stediSftpSdk.CreateUserCommand({
description: "Trading partner Alice",
homeDirectory: "/alice",
}),
);
// Print the user object
console.log(createUserOutput);
The response will look like this.
{
"username": "WL9F11A9",
"homeDirectory": "/alice",
"description": "Trading partner Alice",
"bucketName": "565460e4-4c6f-4a55-87f1-a9d27616f8aa-sftp",
"endpoint": "transfer.us.stedi.com",
"password": "k9TqUSvZsGPs9iav"
}
Connect to the SFTP endpoint
Feedback
Have an idea for something we could improve? Page not clear? We love feedback - send us a message.