
🚀 Revolutionize File Transfers with `scp_util.sh` 🚀
Table of Contents
Intro
Transferring files securely between local and remote systems is a common task for developers, system administrators, and IT professionals. While scp
(Secure Copy Protocol) is a powerful tool for this purpose, remembering and typing all the necessary command-line options can be cumbersome. To simplify this process, we developed scp_util.sh
, a utility script that streamlines file transfers with added features like SSH key support, progress display, and persistent configuration.
scp_util.sh
?
Why Use scp_util.sh
addresses several common challenges associated with using scp
:
- Ease of Use: Provides an interactive interface that prompts for essential details and saves configurations for future use.
- SSH Key Support: Supports the use of SSH keys for authentication, enhancing both security and convenience.
- Progress Display: Displays a progress bar during file transfers if
pv
(pipe viewer) is installed. - Persistent Settings: Remembers frequently used paths and SSH details, reducing repetitive input.
scp_util.sh
Features of - Interactive Prompts: Guides the user through entering the source and destination paths.
- SSH Key Authentication: Allows specifying an SSH key for secure connections.
- Progress Bar: Utilizes
pv
for a visual representation of transfer progress. - Configuration Persistence: Remembers SSH details and paths for future sessions.
- Bidirectional Transfers: Supports both local-to-remote and remote-to-local file transfers.
scp_util.sh
How to Use Step 1: Make the Script Executable
First, ensure that the script is executable by running the following command:
chmod +x scp_util.sh
Step 2: Run the Script with Options
You can run the script with various options to tailor the transfer to your needs:
./scp_util.sh -r -P 2222 -l 1000 -p -v -k /path/to/ssh/key
scp_util.sh
Detailed Walkthrough of Options Parsing
The script starts by parsing command-line options using getopts
. This allows users to specify flags like -r
for recursive copy, -P
for port, -l
for bandwidth limit, -p
for preserving file attributes, -v
for verbose mode, and -k
for specifying an SSH key.
Configuration Loading
If a configuration file exists, the script loads saved SSH details and paths, reducing the need for repetitive input.
SSH Details and Paths Prompts
The script prompts the user to enter the SSH username and host, as well as the source and destination paths. These details are saved for future use.
Transfer Direction
Users are prompted to specify the transfer direction: local to remote or remote to local. This ensures flexibility in file transfers.
Command Construction
Based on the provided options and user input, the script constructs the appropriate scp
or ssh
command. It includes the SSH key if specified and utilizes pv
for progress display if installed.
Confirmation and Execution
Before executing the transfer, the script asks for user confirmation. Upon confirmation, it executes the command and checks for success or failure.
Repeat or Exit
After each transfer, the script asks if the user wants to transfer another file. If yes, it re-runs the script with the same options, providing a seamless experience.
Example Usage
Let's walk through an example where we transfer a directory from the local system to a remote server using an SSH key and displaying the progress.
Run the Script:
./scp_util.sh -r -k ~/.ssh/id_rsa
Enter SSH Details:
Enter the SSH username: user Enter the SSH hostname or IP: remote.server.com
Specify Transfer Direction:
Do you want to transfer from local to remote or remote to local? (l/r): l
Enter Source and Destination Paths:
Enter the source path: /path/to/local/dir Enter the destination path: /path/to/remote/dir
Confirm and Execute:
About to execute: scp -r -i ~/.ssh/id_rsa /path/to/local/dir user@remote.server.com:/path/to/remote/dir Do you want to proceed? (y/n): y
The script will execute the transfer, showing the progress if pv
is installed.
Conclusion
scp_util.sh
simplifies secure file transfers by providing an interactive, user-friendly interface with persistent settings and progress display. Whether you're a developer, sysadmin, or IT professional, this utility script can save you time and effort while ensuring secure and efficient file transfers.
Give scp_util.sh
a try and streamline your file transfer workflow today!
Download the Script
You can download the scp_util.sh
script from the following link: Download scp_util.sh
Feel free to contribute to its development or suggest enhancements on our GitHub gist.
Happy transferring!
Tags
- #FileTransfer
- #SecureCopy
- #SCP
- #DevOps
- #Automation