Topic "Abort script if local file exists"

Author Message
Gazz
[View user's profile]

Joined: 2016-05-04
Posts: 2
Location: Darwin Australia
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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Just don't start the script in the first place.

See
https://winscp.net/eng/docs/guide_automation_conditional#scripting
https://winscp.net/eng/docs/script_checking_file_existence#local
Gazz
[View user's profile]

Joined: 2016-05-04
Posts: 2
Location: Darwin Australia
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
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License