Automatic Script to Synchronize remote directory to local directory

Advertisement

rileys@unitedtelcom.net
Joined:
Posts:
1
Location:
Kansas

Automatic Script to Synchronize remote directory to local directory

I'm having trouble getting a batch script to work for the synchronize command.
Here is my .bat script:
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\winscplog\WinSCP.log" /ini=nul ^
  /command ^
    "open ftp://xxxx:xxxx@10.x.x.x/" ^
# Synchronize Remote to Local d:\
   "synchronize local -delete // D:\ftproot\SysExpDat\CDR /SysExpDat/CDR" ^
# Disconnect
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%
When I check the logs, it logs in via FTP just fine, however the synchronize command is failing with the following error:
2022-01-14 10:04:30.767 Script: Missing parameter for command 'synchronize'.
I have tried double quotes, single quotes, removing the //, and same error in all instances.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,587
Location:
Prague, Czechia

Re: Automatic Script to Synchronize remote directory to local directory

The error refers to this line:
# Synchronize Remote to Local d:\
Your batch file syntax is wrong.
You have specific instance of this issue:
https://winscp.net/eng/docs/faq_batch_file#newline_escaping
Also, the // should not be there.
The correct syntax would be:
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\winscplog\WinSCP.log" /ini=nul ^
  /command ^
    "open ftp://xxxx:xxxx@10.x.x.x/" ^
    "# Synchronize Remote to Local d:\" ^
    "synchronize local -delete D:\ftproot\SysExpDat\CDR /SysExpDat/CDR" ^
    "# Disconnect" ^
    "exit"

Reply with quote

Advertisement

You can post new topics in this forum