Abort script if local file exists

Advertisement

Gazz
Joined:
Posts:
2
Location:
Darwin Australia

Abort script if local file exists

Hi I need to check if a file exists on the remote server and abort the script if NOT. I am using option "failonnomatch on" which works fine for the remote directory, but I also need to abort the script if the file DOES exist in the local directory. I tried option "failonnomatch off" for the local file but it does not appear to work that way, I was hoping it would just be the opposite to 'on' if the condition was met. Is there a simple option to abort the script if a local file already exists i.e. local file (C:\ssis\triggers\*.TRG) simple example of what I have so far (very basic) below.

This Works
----------------------------------------------------
open sftp://sftptcu:**************@10.253.***.**
cd /data/udaftp/cl-universe/u3/TCU/DEX.TRIGGER
option failonnomatch on
ls /data/udaftp/cl-universe/u3/TCU/DEX.TRIGGER/*.TRG

This Doesn't
-----------------------------------------------------
lcd C:\SSIS\AML\SourceFiles\
option failonnomatch off
lls C:\SSIS\AML\SourceFiles\*.TRG
-----------------------------------------------------

Thanks Gazz

Reply with quote E-mail

Advertisement

Gazz
Joined:
Posts:
2
Location:
Darwin Australia

Re: Abort script if local file exists

Yes I created a batch file to check the local directories and if file is not there it calls my WinSCP batch which contains the 'failonnomatch' option. That works well enough.

One issue I did have is in the script below. I set the delete option for both .TRG files but it seems they were both deleted after the 'first' file transfers, causing the second .TRG to fail. Also any further sessions in the script fail after the second .TRG is not found. Can I force the script to keep running or is it better to just delete the two .TRG files as single session at the end of the entire script?

open sftp://sftptcu:**************@10.253.***.**
cd /udaftp/cl-universe/u3/TCU/DEX.TRIGGER
option transfer ascii
get -delete TCU.AML.TRG C:\SSIS\AML\SourceFiles\
close

open sftp://sftptcu:**************@10.253.***.**
cd /udaftp/cl-universe/u3/TCU/DEX.TRIGGER
option transfer ascii
get -delete TCU.RPD.TRG C:\SSIS\RPD\SourceFiles\
close

open sftp://sftptcu:**************@10.253.***.**
cd /udaftp/DEX.EXTRACTDIR.RPD/TCU
option transfer ascii
get *.* -filemask="* | ACCTRAN; EVENTHISTORY" C:\SSIS\RPD\SourceFiles\
close
exit

Thanks Gazz.

martin wrote:

Reply with quote E-mail

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

Re: Abort script if local file exists

Sorry, I do not understand the problem.

Please attach a full log file showing the problem (using the latest version of WinSCP).

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

You can post new topics in this forum