@echo off
:start
ssh -p 22 -N -D 5060 username@server-ip
echo Connection lost. Reconnecting...
timeout /t 5 /nobreak > nul
goto start
This batch file uses a loop to continuously attempt to connect to the SSH server. When the connection is lost, the batch file will wait for 5 seconds (specified by the timeout command) before attempting to reconnect. The > nul part of the timeout command is used to hide the output message.
Save this script in a text editor as ssh_reconnect.bat, and then run it from the command prompt by navigating to the directory where the script is saved and typing ssh_reconnect.bat.
You can customize the timeout value as needed to adjust the time between reconnection attempts. Additionally, you can modify the echo message to display a different message when the connection is lost.