Technical Notes

Automated File Transfer Between Linux and Windows Environments With WinSCP

2024-01-14

File transfer between Linux and Windows environments can be automated with the WinSCP application and Windows batch files.

For the script to work, the WinSCP.com and WinSCP.exe files must be copied to the folder where the batch files are located.

Example of files included in the Scripts folder.

C:\Scripts\BackupVM831.bat
C:\Scripts\WinSCP.com
C:\Scripts\WinSCP.exe

BackupVM831.bat file contents.

@ECHO OFF
COLOR 0C
ECHO SECURITY COPY
ECHO Data saved on virtual machine VM831 to be copied to external hard drive S:\S283.
ECHO BackupVM831.bat
ECHO.
PAUSE
ECHO Copy files located in the /myusername/Documents/ folder.
PAUSE
winscp.com /ini=nul /command "open sftp://myusername:mypassword@192.168.56.131/ -hostkey=""ssh-ed25519 255 jxoFJSgvnIE+dW04Reg1VXKmx09Po+DgJDZBokLXWGM""" "synchronize local -delete S:\S283R152\VM831\myusername\Documents /home/myusername/Documents" "exit"
PAUSE

ECHO Copy files located in the /var/www/html/ folder.
PAUSE
winscp.com /ini=nul /command "open sftp://myusername:mypassword@192.168.56.131/ -hostkey=""ssh-ed25519 255 jxoFJSgvnIE+dW04Reg1VXKmx09Po+DgJDZBokLXWGM""" "synchronize local -delete S:\S283R152\VM831\html /var/www/html" "exit"
PAUSE

The management of back-up copies using well-programmed scripts means that the task can be carried out quickly and accurately.

Be careful with my technical notes

My technical notes are not tutorials. They are reminders of commands to be executed from a terminal. I do not provide any explanation of the nature of the commands described in my documents. Do not execute them if you don’t understand the meaning of the commands. To avoid losing data or destabilising your workstation, it is preferable to test the commands from a virtual machine, with snapshots.

The names of directories and IP addresses must match the configuration of your workstation and peripherals.

Ghislain Coutu

Graphic designer, programmer, multimedia integrator, technical writer.

LinkedIn