Quick Storage API in Bash with the SFTP cloud storage
Published {$created} by Carsten Blum
Sometimes you don’t need a full application or a script written in Go, PHP, or Python.With just a few command-line tools already available on macOS or Linux, you can use ftpGrid cloud FTP storage as your storage API for quick file backups.
This is perfect for developers, sysadmins, or anyone who wants to automate backups without installing extra dependencies.
Before starting this tutorial, you need an account with ftpGrid, which is a simple process outlined in our getting started with FTP/SFTP guide. If your are in doubt if managed FTP/SFTP hosting is for you, you can read our guide to ftpGrid's managed hosting.
Requirements
A macOS or Linux machine (Ubuntu/Debian works out of the box)
SFTP available in your terminal (
which sftp
)An ftpGrid account with SFTP credentials
Step 1: Create a test file
echo "Hello from Bash and ftpGrid!" > hello.txt
Step 2: Upload a single file with SFTP
sftp PREFIX.username@edge1.ftpgrid.com:/uploads/ << EOF
put hello.txt
bye
EOF
This connects to ftpGrid and uploads hello.txt
into /uploads
.
Step 3: Upload multiple files at once
If you have a folder of backups:
sftp PREFIX.username@edge1.ftpgrid.com:/uploads/ <<EOF
mput *.txt
bye
EOF
The command mput
uploads all .txt
files in the current directory.
Step 4: Automating backups with cron
To run a backup every night at 2 AM, add this to your crontab:
0 2 * * * sftp PREFIX.username@edge1.ftpgrid.com:/backups/ <<EOF
mput /home/youruser/documents/*.pdf
bye
EOF
Step 5: Using scp
as an alternative
For quick, one-line uploads you can also use scp
:
scp hello.txt your_username@edge1.ftpgrid.com:/uploads/
To upload a folder recursively:
scp -r my_folder/ your_username@edge1.ftpgrid.com:/uploads/
Conclusion
With just a few lines in your terminal, you can back up files to ftpGrid’s cloud FTP storage.Whether it’s one file, multiple files, or a scheduled job, using SFTP or SCP from Bash gives you a lightweight and secure Storage API without writing a single line of application code.
Get started today with our Quick Start guide and explore the full FTP Cloud Storage page for more use cases.