Recently, I joined a new business team to learn and handle some new technologies. One of my tasks involves fetching data from a database, generating a JSONLines file, and then sending it to the Bloomreach PATCH API via SFTP using a cron job. The repository has been under development for more than two years, but it lacks beginner-friendly documentation to explain what SFTP is or how it works within this project. After struggling for two days, I finally figured it out, and I want to share my experience here, along with a general use case example.
Steps:
1, Download the FileZilla Client from the official website.
2, Set Up an SFTP Server:
- Refer to this image to create and run an SFTP Server container from the docker hub: atmoz-sftp, if you want to know more about it, here is the GitHub repo.
- Generate an SSH key pair: Create a private key
sftp_rsa
and a public keysftp_rsa.pub
. Store them in a directory, e.g.,~/Downloads/sftp/keys
. - Pull the Docker image,
docker pull atmoz/sftp
. - Choose a hostname: use "foo" for the client and "19" as the port.
3, Run the Docker Container:
- Use the command below to start the docker container, mount the volumes to transfer the public key to the server, and share files between the localhost and Docker container:
docker run \
-v ~/Downloads/sftp/keys/sftp_rsa.pub:/home/foo/.ssh/keys/sftp_rsa.pub:ro \
-v ~/Downloads/share:/home/foo/share \
-p 19:22 -d atmoz/sftp \
foo::1001
4, Configure FileZilla Client:
- Start FileZilla Client: Go to File → Site Manager → My Sites (create a name) → General → Set the following:
- Protocol: SFTP
- Host: localhost
- Port: 19
- Logon type: Key file
- User: foo
- Key file: Browse and select the private key
sftp_rsa
- Click Connect.
5, Verify Connection:
- You should see the message “Status: Directory listing of
/share
successful" in the FileZilla dashboard. The remote site/share
folder should reflect the files from your local~/Downloads/share
folder.
6, Troubleshooting:
- If you encounter issues, use the following commands to check the status and logs of the Docker container:
docker ps
docker logs <CONTAINER ID>