vi transfer_file.sh
#!/bin/bash
# Prompt for file path and server details
read -p "Enter the full path of the file to transfer (e.g., C:/Users/YourUsername/Desktop/myfile.txt): " file_path
read -p "Enter the Linux server username (e.g., oracle): " linux_user
read -p "Enter the Linux server IP address (e.g., 192.168.1.1): " linux_server
read -p "Enter the target directory on the Linux server (e.g., /tmp): " target_dir
# Path to the pscp executable (Make sure you have pscp.exe from the PuTTY installation)
PSCP_PATH="/path/to/pscp.exe"
# Use pscp to transfer the file
"$PSCP_PATH" "$file_path" "$linux_user"@"$linux_server":"$target_dir"
# Check if the transfer was successful
if [ $? -eq 0 ]; then
echo "File transferred successfully!"
else
echo "File transfer failed. Please check your details."
fi
bash transfer_file.sh
Transfer_file_with_directories.sh
@echo off
setlocal
REM Set your variables
set SERVER=your_linux_server_address
set USER=your_username
set PASSWORD=your_password
set LOCAL_FOLDER=C:\path\to\your\local\
set REMOTE_DIR=/path/to/remote/directory/
REM Set the path to WinSCP executable (make sure WinSCP is installed and the path is correct)
set WINSCP_PATH="C:\Program Files (x86)\WinSCP\WinSCP.exe"
REM Create a temporary script file for WinSCP commands
echo open sftp://%USER%:%PASSWORD%@%SERVER% > transfer_script.txt
echo option batch abort >> transfer_script.txt
echo option confirm off >> transfer_script.txt
REM Recursive file and directory transfer
echo Synchronizing local folder to remote directory... >> transfer_script.txt
echo synchronize remote "%LOCAL_FOLDER%" "%REMOTE_DIR%" >> transfer_script.txt
REM Execute the transfer using WinSCP
"%WINSCP_PATH%" /script=transfer_script.txt
REM Check if the transfer was successful
if %ERRORLEVEL% EQU 0 (
echo File transfer completed successfully.
) else (
echo File transfer failed. Please check the log for errors.
)
REM Cleanup: Remove the temporary script file
del transfer_script.txt
endlocal
No comments:
Post a Comment