Update sftp_transfer

This commit is contained in:
vijay 2025-05-08 01:47:17 +00:00
parent 361fb58a2a
commit d0a17d9b82

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
# wget https://git.technozone.com.au/vijay/Scripts/raw/branch/main/sftp_transfer -O sftp_transfer.sh && chmod +x sftp_transfer.sh && ./sftp_transfer.sh && rm sftp_transfer.sh # wget https://git.technozone.com.au/vijay/Scripts/raw/branch/main/sftp_transfer -O sftp_transfer.sh && chmod +x sftp_transfer.sh && ./sftp_transfer.sh && rm sftp_transfer.sh
# Function to display the menu # Function to display the menu
show_menu() { show_menu() {
echo "==============================" echo "=============================="
@ -25,15 +26,29 @@ zip_folder() {
fi fi
} }
# Function to list available zip files
list_zip_files() {
echo "Available zip files:"
ls *.zip 2>/dev/null
}
# Function to transfer the zipped file to a remote server # Function to transfer the zipped file to a remote server
transfer_file() { transfer_file() {
read -p "Enter the remote server username: " username read -p "Enter the remote server username: " username
read -p "Enter the remote server address: " server_address read -p "Enter the remote server address: " server_address
read -p "Enter the remote directory to upload the file: " remote_dir read -p "Enter the remote directory to upload the file: " remote_dir
read -sp "Enter the password for the remote server: " password
echo
# List available zip files
list_zip_files
# Prompt user to select a zip file
read -p "Enter the name of the zipped file to transfer (with .zip): " zip_name read -p "Enter the name of the zipped file to transfer (with .zip): " zip_name
if [ -f "$zip_name" ]; then if [ -f "$zip_name" ]; then
sftp "${username}@${server_address}" <<EOF # Use sshpass to provide the password for SFTP
sshpass -p "$password" sftp -v "${username}@${server_address}" <<EOF
put "$zip_name" "$remote_dir" put "$zip_name" "$remote_dir"
bye bye
EOF EOF