Script with multiple get/put

Advertisement

FES
Guest

Script with multiple get/put

Hello,

my task is to connect to an SFTP site, change local/external directory, put all files, change directories again, put all files etc.

Everything works fine, unless the source directory is empty, I'll get the message "No files matching ‘*’ found." and the script halts with a WinSCP prompt, so it won't continue with the next command.
I have set the batch on option.

Here's is my bat-file:
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="E:\xc_prod\FTP\wam_ftp\Kunde.txt" /loglevel=1 /ini=nul ^
  /command ^
 
    "open sftp://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^
    "option batch on" ^
   "echo ====================desadv====================" ^
    "lcd E:\xc_prod\FTP\wam_ftp\in\Kunde\desadv\" ^
    "cd ../DELIVIN" ^
    "put -delete DELIVIN* ./ " ^
   
   "echo ====================invoice====================" ^
    "lcd E:\xc_prod\FTP\wam_ftp\in\Kunde\invoice\" ^
    "cd ../INVIN" ^
    "put -delete INVIN* ./ " ^
   
   
   "echo ====================ordrsp====================" ^
    "lcd E:\xc_prod\FTP\wam_ftp\in\Kunde\ordrsp\" ^
    "cd ../ORDCONFIN" ^
    "put -delete ORD* ./ " ^
   
   "echo ====================orders====================" ^
    "lcd E:\xc_prod\Source\Application\incoming\" ^
    "cd ORDOUT" ^
    "get -delete ORDOUT* ./ " ^
   "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

Reply with quote

Advertisement

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

Re: script with multiple get/put

The "No file matching ‘*’ found" message is by default not an error, it does not abort the script.

The script does not continue, because you are not escaping the line breaks after the empty lines in your batch file.
It should be like:
    "put -delete DELIVIN* ./ " ^
    ^
    "echo ====================invoice====================" ^
See https://winscp.net/eng/docs/faq_batch_file#newline_escaping
In other words, the batch file would stops always, even if the files were found.

Reply with quote

FES
Guest

Re: script with multiple get/put

Hi Martin,

thank you very much, that did the trick. I like to have some blank lines for readability/structure. I have just deleted them.

Reply with quote

Advertisement

You can post new topics in this forum