Copy data from bloomberg sft with winscp cmd

It is a little bit tricky to run winscp command. Here is a working example:

  1. connect and authenticate with pre shared key
  2. synchronize all except bin,etc
  3. exit with correct exit code
  4. eventually run powershell script
@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%