Using Stedi SFTP from the command line
Updated July 5, 2022
This example shows how to use the SFTP service from the command line.
Authentication
Create an API key if you haven’t done so already. The examples on this page assume you have your API key stored in an environment variable called STEDI_API_KEY
. You can do that with the following command.
export STEDI_API_KEY=replace.withYourOwnApiKey
Create an SFTP user
Create a user by calling the Stedi SFTP API. You can customize description
and homeDirectory
.
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 of it.
curl --request POST 'https://api.sftp.us.stedi.com/2022-04-01/users' \
--header "Authorization: Key ${STEDI_API_KEY}" \
--header 'Content-Type: application/json' \
--data-raw '{
"homeDirectory": "/directory/for/partner1",
"description": "Trading Partner 1"
}'
The response will look something like this.
{
"username": "WL9F11A9",
"homeDirectory": "/directory/for/partner1",
"description": "Trading Partner 1",
"bucketName": "565460e4-4c6f-4a55-87f1-a9d27616f8aa-sftp",
"endpoint": "data.sftp.us.stedi.com",
"password": "k9TqUSvZsGPs9iav"
}
Connect to the SFTP server
You can use the returned credentials to connect to the SFTP server. You can use whichever SFTP client you prefer. In this example, we’ll access the server from the command line.
sftp WL9F11A9@data.sftp.us.stedi.com
The client will ask for your password. After that, you will see the following prompt.
sftp>
You can type in commands to interact with the SFTP server. If you’re not familiar with SFTP commands, here are a few common ones to get you started.
Command | Description |
---|---|
pwd | Show the name of the active directory on the SFTP server. |
lpwd | Show the name of the active directory on your local machine. |
ls | List the contents of the active directory on the SFTP server. |
lls | List the contents of the active directory on your local machine. |
cd | Change the active directory on the SFTP server, e.g. cd documents . |
lcd | Change the active directory on your local machine, e.g. cd documents . |
mkdir | Create a directory on the SFTP server, e.g. mkdir documents . |
get | Download a file from the SFTP server to your local machine, e.g. get file.txt . |
put | Upload a file from your local machine to the SFTP server, e.g. put file.txt . |
rename | Change the name of a file on the SFTP server, e.g. rename file.txt document.txt . |
rm | Remove a file from the SFTP server, e.g. rm document.txt . |
bye | Disconnect from the SFTP server. |