IBM Support

Logging Success or Failure in OpenSSH Batch Mode File Transfers

Troubleshooting


Problem

This document contains a sample CL program that logs success or failure in OpenSSH batch mode file transfers.

Resolving The Problem

This document assumes that public key authentication is configured and is successful for SFTP or SCP. For additional information, refer to Rochester Support Center knowledgebase document:

N1012710, Configuring the System i SSH, SFTP, and SCP Clients to Use Public-Key Authentication:

The following is a sample CL program that logs success or failure in OpenSSH batch mode file transfers:

Prerequisites

SI25208 (V5R3)
SI25209 (V5R4)
5722SS1 Option 30 (Qshell)

Example

PGM                                                                    
DCL     VAR(&RC)     TYPE(*INT)  LEN(4)                                
DCL     VAR(&MSGID)  TYPE(*CHAR) LEN(7)                                
DCL     VAR(&MSGDTA) TYPE(*CHAR) LEN(4)                                
DCL     VAR(&CM3)    TYPE(*CHAR) LEN(78)                              
DCL     VAR(&CM31)   TYPE(*CHAR) LEN(24) +                            
            VALUE('/QOpenSys/usr/bin/sftp')                        
DCL     VAR(&CM32)   TYPE(*CHAR) LEN(33) VALUE('-b +                  
                     /home/someuser/FTP_Script.txt')                  
DCL     VAR(&CM33)   TYPE(*CHAR) LEN(21) VALUE('someuser@1.10.38.17')
CHGVAR  VAR(&CM3) VALUE(&CM31 *CAT &CM32 *CAT &CM33)                  
QSH CMD(&CM3)                                                              
RCVMSG MSGTYPE(*COMP) RMV(*NO) MSGDTA(&MSGDTA) MSGID(&MSGID)                
IF (&MSGID *EQ 'QSH0005') +                                                
    CHGVAR &RC %BIN(&MSGDTA)                                                
IF (&RC *EQ 0) THEN(DO)                                                                
    SNDMSG MSG('The file transfer completed successfully.') TOUSR(user_profile)
               ENDDO                                                        
IF (&RC *GE 1) THEN(DO)                                                    
    SNDMSG MSG('The file transfer failed') TOUSR(user_profile)                  
               ENDDO                                                        
ENDPGM                                                                      

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"6.1.0"}]

Historical Number

473277768

Document Information

Modified date:
18 December 2019

UID

nas8N1018799