Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Error code 0 if get doesn't find any file

Apollogz wrote:

Still shows %ERRORLEVEL% even when a file is found. Does not work.

Show us your batch file.
Apollogz

Re: Error code 0 if get doesn't find any file

ptolomeoo wrote:

Yes, if you execute a command, you can specify option failonnomatch on and the command will return an error 1 instead of 0 if no wildcard file is found.

Example:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /log="C:\temp\winscp_output.log" /command "open YOUR_FTP_PROFILE" "option failonnomatch on" "put C:\temp\*.txt /" "exit"

Still shows %ERRORLEVEL% even when a file is found. Does not work.
ptolomeoo

Re: Error code 0 if get doesn't find any file

jr wrote:

Is it possible to have an error when the directory is empty or no file has been downloaded ?


Yes, if you execute a command, you can specify option failonnomatch on and the command will return an error 1 instead of 0 if no wildcard file is found.

Example:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /log="C:\temp\winscp_output.log" /command "open YOUR_FTP_PROFILE" "option failonnomatch on" "put C:\temp\*.txt /" "exit"
martin

Re: Error code 0 if get doesn't find any file

jr wrote:

Problem : if no file has been found in /home/test/ using a filter like *, the return code is 0.

The script return an error (code 1) when I use (test.csv doesn't exist):
"get -delete /home/test/test.csv d:\"

That's correct.

See https://winscp.net/eng/docs/scriptcommand_get
When specific file name is used, command fails when the file does not exist. When wildcard is used, command succeeds, without doing anything, if the wildcard does not match any file.


Is it possible to have an error when the directory is empty or no file has been downloaded ?

No. You have to check yourself if any file is present, in advance. Or if any file was downloaded, ex post.
jr

Error code 0 if get doesn't find any file

Hello everybody,

I'm new here and I hope I can get a solution for my issue :

I have a script that upload or download a file on a remote computer using WinSCP and SFTP. The file in question has a variable name so I have to use a filter.

I use the following command to download the file on the remote computer :
"get -delete /home/test/*.csv d:\"


Problem : if no file has been found in /home/test/ using a filter like *, the return code is 0.

The script return an error (code 1) when I use (test.csv doesn't exist):
"get -delete /home/test/test.csv d:\"


Is it possible to have an error when the directory is empty or no file has been downloaded ?

Thanks for your help,

Julien