Exclude files with .tmp extension while getting files

Advertisement

di
Joined:
Posts:
1

Exclude files with .tmp extension while getting files

I need to retrieve the files excluding *.tmp files from remote server. The files should be deleted which got retrieved.
I went through filemask topic and prepared below commands in batch script.
echo open %USERIDPASS% -hostkey="*" -timeout=100 -passive=on > %COMMAND_FILE%
echo %TRANSFER_TYPE% >> %COMMAND_FILE%
echo cd %REMOTE_DIR%>> %COMMAND_FILE%
echo lcd %LOCAL_DIR%>> %COMMAND_FILE%
echo get -delete %REMOTE_FILE%|*.tmp >>%COMMAND_FILE%
echo bye >> %COMMAND_FILE%
 
echo winscp/script=%COMMAND_FILE% >> %LOGDIR%\%LOGFILE%
"C:\Program Files (x86)\WinSCP\WinSCP.com"/ini=nul /script=%COMMAND_FILE% >> %LOGFILE%
But the get command is not working as expected, can anyone help with this.

Reply with quote

Advertisement

Guest

Re: Exclude files with .tmp extension while getting files

Hi Martin, I have tried the command you have given but it is reporting as below when executing the batch script:
I am setting REMOTE_FILE =*.*
command:
get -delete %REMOTE_FILE% -filemask=|*.tmp >>%LOGDIR%\%COMMAND_FILE%
error reporting during execution of batch script in cmd:
d:\>echo get -delete *.* -filemask=  | *.tmp  1>>commandfilename
'*.tmp' is not recognized as an internal or external command,
operable program or batch file.
I also need to exclude some directories while getting the files but it is not working as expected:
command:
echo get -delete %REMOTE_FILE% -filemask=|/hs/test/outgoing/rtfspool/ >> %LOGDIR%\%COMMAND_FILE%
error reporting during execution of batch script in cmd:
d:\>echo get -delete *.* -filemask=  | /hs/test/outgoing/rtfspool/  1>>commandfilenamewithpath
'/hs/test/outgoing/rtfspool/' is not recognized as an internal or external command,
operable program or batch file.
command:
echo get -delete %REMOTE_FILE% -filemask=|/hs/test/outgoing/rtfspool >> %LOGDIR%\%COMMAND_FILE%
error reporting during execution of batch script in cmd:
d:\>echo get -delete *.* -filemask=  | /hs/test/outgoing/rtfspool  1>>commandfilenamewithpath
The system cannot find the path specified.
Could you please suggest where the issue is happening in above commands.

Thanks in advance.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,469
Location:
Prague, Czechia

Re: Exclude files with .tmp extension while getting files

This is more Windows batch file question than WinSCP question.
The | is pipe operator in batch file.
You need to escape it with ^:
echo get -delete %REMOTE_FILE% -filemask=^|*.tmp >>%COMMAND_FILE%

Or consider, if you really need to generate the WinSCP script file. You can use environment variables right in the WinSCP script file.
https://winscp.net/eng/docs/scripting#variables

Reply with quote

Advertisement

You can post new topics in this forum