It is a little bit tricky to run winscp command. Here is a working example:
- connect and authenticate with pre shared key
- synchronize all except bin,etc
- exit with correct exit code
- eventually run powershell script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
@echo off "C:\Path\WinSCP.com" ^ /log="C:\Path\WinSCP.log" /ini=nul ^ /command ^ "open sftp://username@sftp.bloomberg.com/ -hostkey=""ssh-rsa 2048 AA:BB:CC:DD:EE:FF:AA:BB:CC:DD:EE:FF:00:00:00:00"" -privatekey=""C:\Path\bloomberg.ppk""" ^ "synchronize -filemask=""|/bin/;/etc/"" local ""SFTP"""^ "exit" set WINSCP_RESULT=%ERRORLEVEL% if %WINSCP_RESULT% equ 0 ( echo Success ) else ( echo Error ) powershell -file sync2r.ps1 exit /b %WINSCP_RESULT% |