@ECHO OFF
SETLOCAL
set /a count=5
set "filelist="
echo hello1
for /f "delims=" %%a in ('dir /s /r /b /a-d /o:-d "C:\09\Batch Scripting" ') do if defined count set "filename=%%a" &call :transfer
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/command ^
"open sftp://username:password@X.X.X.X/ -hostkey=""ssh-rsa 1024 blah blah=""" ^
"put %filelist% /users/sftpuser/ " ^
"exit"
pause
goto :eof
:transfer
echo %filename%
set "filelist=%filelist% "%filename%""
set /a count-=1
if %count%==0 set "count="
goto :eof
The batch file successfully authenticates the connection, but later is fails with message:
The filename, directory name, or volume label syntax is incorrect