File Transfer Script over SFTP in Windows

I will give an example of a file transfer script via SFTP in Windows.

1) Install WinSCP

2) Connect to the host once so that the key gets into the cache.

3) Create a tftp.bat file with the contents:

@echo off
CD "C:\Program Files (x86)\WinSCP" /ini=nul /script=D:\test\script.txt

4) Create a script.txt, for example, with contents (the script copies the file D:\test\file1.txt to the server in the user’s home directory, and file2.txt downloads from the server):

option echo off 
option batch on 
option confirm off
open sftp://ixnfo:test@ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
lcd "D:\test\"
put -nopermissions -nopreservetime "D:\test\file1.txt" "/home/ixnfo/"
get "/home/ixnfo/file2.txt" "D:\test\"

To check, run the script from the Windows command line:

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply