IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SFTP Return Codes


IBM Mainframe Forums -> TSO/ISPF
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
NEW2MAIN

New User


Joined: 20 Apr 2023
Posts: 7
Location: United States

PostPosted: Thu Apr 24, 2025 11:49 pm
Reply with quote

I am using COZBATCH as my SFTP utility
5650-ZOS
ISPF 7.4

No matter what I do to try to get my SFTP job to fail, I keep getting the following:

CoZBatchÝI¨: returning rc=exitcode=0

I have changed the server address (incorrect )
I have changed the remote directory (non-existent)
I have changed the file name (incorrect and non-existent)

Any combination of those changes should result in a condition or exitcode of 1. It does not. I am consistently getting a code of 0.

Can someone please tell me why this is happening. I am trying to make the job fail so i can manipulate the in conditions of a dependent job so it will not run if the previous job (SFTP job) has a condition code greater than 0000.
Back to top
View user's profile Send private message
AlexSalas95

New User


Joined: 18 Mar 2024
Posts: 21
Location: United States

PostPosted: Wed Dec 24, 2025 9:42 pm
Reply with quote

@NEW2MAIN I'm assuming by now you've figured this out or have some other workaround/solution, so I'll put this out for progeny.

Unless you specifically capture and handle the return code for a particular command, the script will return the result of the last command executed.

For example, cd'ing to a non-existent directory should result in an rc=1; however, if afterward you echo out an error message, that command executes successfully, and the result is an rc=0.

This is a bit dangerous. To demonstrate, let's assume the current directory is as follows;

Code:
$ ls
 folder1 folder2 text.txt


Now consider the following script;

Code:
$ cd folder3 # this does not exist
$ mkfile newtext.txt


Note that folder3 does not exist. So, what happens? Well, the error is written to the log, but the script continues. The newtext.txt file is created in the active directory. So now the current directory looks like this;

Code:
$ ls
 folder1 folder2 newtext.txt text.txt


Also, since the mkfile and ls commands were executed successfully, the return code for the script is 0.

There are probably several ways to handle this. Perhaps the best way is if there is an environment variable/parameter that will exit the script as soon as a command fails. I'm not sure if such a way exists. However, the way I've handled it is to capture and process the return code for commands deemed critical for the execution of the script. You can reference the return code (more specifically, the exit code, but that semantics) for the previously executed command by the $? shell variable. This is how that would look;

Code:
$ cd folder3 # this does not exist
if $? > 0 ; then
   exit
fi
$ mkfile newtext.txt
$ ls


When the above is executed, the return code will be rc=1, and neither the mkfile nor ls commands are executed. To set a different return code, simply follow the exit command with the code, like "exit 8" to return rc=8.

To make the code more modular and less repetitive, you could move the logic to check the return code into a function and call this function after each critical command is called. That way, you are sure to exit the script when something goes wrong and get the corresponding return code.

Hopefully this is helpful to someone, and if somebody knows of a better way, feel free to share!
Back to top
View user's profile Send private message
AlexSalas95

New User


Joined: 18 Mar 2024
Posts: 21
Location: United States

PostPosted: Wed Dec 24, 2025 9:47 pm
Reply with quote

To put it simply, add logic to check the exit codes using the $? shell variable, and specify return codes using exit $? or exit x, where x is the desired return code.
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> TSO/ISPF

 


Similar Topics
Topic Forum Replies
No new posts Using JOINKEYS - Exclude accounts whi... SYNCSORT 10
No new posts purge jobs with return code 0 and ret... JCL & VSAM 6
No new posts batch SFTP job using AOPBATCH unable ... All Other Mainframe Topics 7
No new posts BPXBATCH SFTP to remote path having s... All Other Mainframe Topics 6
No new posts Binary File format getting change whi... All Other Mainframe Topics 7
Search our Forums:


Back to Top