I am trying to use a batch file to copy and replace a file from a SFTP site to a local C:\ using a batch file and Task Scheduler. This is being run on Windows Data Center 2019:
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Users\xxxxxXxxxxxxxx\xxxxxxxxx\xxxxxxxxxx" /ini=nul ^
/command
"open sftp://xxxxxxxx/xxxxxxxx/ -hostkey=""xxxx""" ^
"cd /foldercontainingfiletobecopied" ^
"copy /thefolder/thetxttobecopied C:\destinationfolder\*" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
After running the batch file, I get the following error:
Unknown command 'copy'
'"exit"' is not recognized as an internal or external command, operable program or batch file.
Any ideas of how to fix this issue or a better way to copy and replace the file? I have tried the following with no success:
xcopyget/putcp
