mel3kings
mel3kings

Reputation: 9405

How to ignore failure when file does exist when downloading with WinSCP script

Running a script to get a file from SFTP server, however this is recurring job and should still succeed if no file exist, is there an option I can specify?

option batch on
option confirm off
option transfer binary
open sftp://server -timeout=60
password
get /File/2_04-28-2015.txt  D:\Files
close
exit

Getting this result:

Can't get attributes of file 'File/2_04-28-2015.txt'.
    No such file or directory.
    Error code: 2

Tried setting failonnomatch:

winscp> option failonnomatch on
Unknown option 'failonnomatch'.

Upvotes: 1

Views: 5714

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202222

You cannot tell WinSCP to ignore absent file, when using a specific file name.

But you can check the file existence prior to the actual download.


Easy alternative hack is to use a file mask (note the trailing *) and set the failonnomatch off:

option failonnomatch off
get /File/2_04-28-2015.txt*  D:\Files\

(if you are getting "Unknown option 'failonnomatch'", then you have an old version of WinSCP).

Upvotes: 2

Richard Auger
Richard Auger

Reputation: 44

Have you tried using MGET instead of GET? It shouldn't fail, just not transfer anything if there's nothing there.

Upvotes: 0

Related Questions