Monday, 20 January 2025

Transfer file from Linux server to Windows server



 #!/bin/bash

# Windows machine details
WIN_USER="wasiq"              # Your Windows username
WIN_PASS="password123"        # Your Windows password
WIN_HOST="192.168.1.100"      # IP address or hostname of the Windows machine (can also use the Windows machine's hostname)
WIN_REMOTE_DIR="C:/Users/wasiq/Desktop"  # The directory on your Windows machine where the file will be saved

# Linux details
LINUX_FILE="/path/to/linux/file/myfile.tar.gz"  # The file on your Linux server you want to transfer

# Use sshpass to provide the password and run the sftp command
sshpass -p "${WIN_PASS}" sftp -v ${WIN_USER}@${WIN_HOST} << EOT
lcd ${WIN_REMOTE_DIR}      # Local directory on Windows where the file will be saved
get "${LINUX_FILE}"        # Transfer the file from the Linux server to the Windows machine
bye                        # End the sftp session
EOT



No comments:

Post a Comment