Error code 0 if get doesn't find any file

Advertisement

jr
Guest

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
  • download_20140429_165837.log (8.05 KB, Private file)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

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.

Reply with quote

ptolomeoo
Guest

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"

Reply with quote

Apollogz
Guest

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.

Reply with quote

martin
Site Admin
martin avatar

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.

Reply with quote

Advertisement

You can post new topics in this forum