Developer SFTP in Linux CLI: Quick Start
Published {$created} by Viggo
For developers, automating file transfers and backups is essential. The Linux command-line interface (CLI) provides powerful tools for this, and SFTP (Secure File Transfer Protocol) is the gold standard for secure transfers. This guide provides a quick start for using SFTP in your Linux CLI workflows with ftpGrid.
What is SFTP and Why Use It?
SFTP combines file transfer capabilities with SSH encryption, providing a secure channel for data transfer. It’s a significant upgrade over older protocols like FTP and even FTPS, offering enhanced security and reliability. If you'll be dealing with any sensitive information, SFTP is the recommended method. Our features page https://ftpgrid.com/features/ details the robust security measures we implement.
Basic SFTP Commands in Linux
The sftp command is your primary tool for SFTP interactions. Here are some basic commands to get you started:
sftp user@edgeN.ftpgrid.com: Connect to your ftpGrid server. Replaceuserwith your username.edgeN.ftpgrid.comis your secure endpoint.ls: List files and directories on the remote server.cd directory: Change the current remote directory.pwd: Print the current remote working directory.get remote_file local_file: Download a file from the server. Iflocal_fileis omitted, the file will be downloaded to the current local directory.put local_file remote_file: Upload a file to the server. Ifremote_fileis omitted, the file will be uploaded to the current remote directory.mkdir directory: Create a directory on the remote server.rm file: Remove a file from the remote server.exit: Close the SFTP connection.
Example:
To upload a file named my_script.py to your home directory on your ftpGrid server:
sftp user@edgeN.ftpgrid.com
put my_script.py
exit
Automating SFTP with Scripts and SSH Keys
For automated backups and deployments, scripts are invaluable. Using SSH keys eliminates the need to enter passwords, making automation seamless.
-
Generate an SSH Key Pair:
If you don't have one already, create an SSH key pair. See our guide https://ftpgrid.com/tutorials/create-ssh-keys-for-sftp-scp-authentication/ for detailed instructions.
-
Add Public Key to ftpGrid:
Add your public key to your account settings within the ftpGrid dashboard. This enables passwordless authentication. See our advanced SSH key authentication guide https://ftpgrid.com/tutorials/advanced-ssh-key-authentication-for-sftp/ for further details.
-
Example Script (Bash):
#!/bin/bash # Configuration SFTP_USER="your_username" SFTP_HOST="edgeN.ftpgrid.com" REMOTE_DIR="/backup" LOCAL_DIR="/path/to/local/backup" # Synchronize files sftp -o StrictHostKeyChecking=no $SFTP_USER@$SFTP_HOST << EOF lcd $LOCAL_DIR cd $REMOTE_DIR sync bye EOFNote:
StrictHostKeyChecking=nodisables host key verification and is suitable for automated environments where key changes are expected. For increased security in production environments, incorporate host key verification mechanisms.
Alternative Tools and Considerations
While the sftp command is fundamental, consider tools like rsync (over SFTP) for more advanced synchronization options, especially for large datasets. For scripting, explore our quick storage API series https://ftpgrid.com/tutorials/quick-storage-api-series-sftp-ftp/ that provides snippets and examples in various programming languages (Bash, Perl, C++, C#, Python, Java, PHP, Go).
Ready to get started? Check out our FTP/SFTP quick start guide https://ftpgrid.com/tutorials/ftp-sftp-cloud-storage-quick-start/ and explore our pricing https://ftpgrid.com/pricing/!
Keywords: developer SFTP in linux cli