× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



We have a similar CL "wrapper" system for the db side of the world.

In the CL we set environmental variables that are used in PASE to control the jobs.

As for the sFTP side we shell out to PASE (QP2SHELL) and then control the entire sFTP process with pExpect inside of Python.

Snippet looks like this:

/* Declare variables for QP2SHELL Command */

             DCL        VAR(&CMD) TYPE(*CHAR) LEN(21) +
VALUE('/QOpenSys/usr/bin/sh')

             DCL        VAR(&PARM1) TYPE(*CHAR) LEN(10) VALUE('-c')

             DCL        VAR(&PARM2) TYPE(*CHAR) LEN(65) +
                          VALUE('/apps/runpysftp.sh')

             DCL  VAR(&NULL)   TYPE(*CHAR)   LEN(1) VALUE(X'00')

/* Declare variables for QUSRJOBI API to check qp2batch code */

             DCL        VAR(&JOBI0600) TYPE(*CHAR) LEN(200)
             DCL        VAR(&JOBILEN) TYPE(*INT) LEN(4) VALUE(200)
             DCL        VAR(&ILERC) TYPE(*INT) STG(*DEFINED) LEN(4) +
                          DEFVAR(&JOBI0600 109)

             ADDENVVAR  ENVVAR(CFGPATH) VALUE(&CFGPATH) REPLACE(*YES)

/*  add more env variables here  */

/* Null terminate parameters for QP2SHELL command */

             CHGVAR VAR(&CMD) VALUE(&CMD *TCAT &NULL)

             CHGVAR VAR(&PARM1) VALUE(&PARM1 *TCAT &NULL)

             CHGVAR VAR(&PARM2) VALUE(&PARM2 *TCAT &NULL)

/* Call main shell script

             CALL       PGM(QP2SHELL) PARM(&CMD &PARM1 &PARM2)

             CALL PGM(QUSRJOBI) PARM(&JOBI0600 +
                                     &JOBILEN +
                                     'JOBI0600' +
                                     '*' +
                                     ' ' )

             SNDPGMMSG MSG(%CHAR(&ILERC))

             IF         COND(%BIN(&JOBI0600 109 4) *NE 0) THEN(DO)
             CHGVAR VAR(&TMPVAR) VALUE(%BIN(&JOBI0600 109 4))
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) +
                          MSGDTA('runpysftp Error Occurred') +
                          MSGTYPE(*ESCAPE)
             ENDDO

ENDPGM



Jerry

On 11/29/2022 11:28 AM, Greg Wilburn wrote:
/* This pgm must run under the user profile that matches the username */
/* on the SFTP server. */

PGM
DCLPRCOPT DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR(TBFBIND)

DCL VAR(&SFTP) TYPE(*CHAR) LEN(50)
DCL VAR(&CMD) TYPE(*CHAR) LEN(500)
DCL VAR(&STRING) TYPE(*CHAR) LEN(15)
DCL VAR(&LOG) TYPE(*CHAR) LEN(50)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(4)
DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)

/* These are for EML_STMF */
DCL VAR(&SUBJ) TYPE(*CHAR) LEN(100)
DCL VAR(&STMF) TYPE(*CHAR) LEN(100)
DCL VAR(&TOADDR) TYPE(*CHAR) LEN(50)
DCL VAR(&CCADDR) TYPE(*CHAR) LEN(50)
DCL VAR(&MSG) TYPE(*CHAR) LEN(100)
DCL VAR(&BDYCNT) TYPE(*CHAR) LEN(50)
DCL VAR(&ERRID) TYPE(*INT) LEN(2)

CALLPRC PRC('Txt_DateTimeISO') RTNVAL(&STRING)

CHGVAR VAR(&LOG) VALUE('/ftplogs/NYR000-' +
*CAT &STRING *TCAT '.log')

/* Create Log File <user>-YYYYMMDD-HHMMSS.log IBM Document N1011526 */

CHGVAR VAR(&CMD) VALUE('/QOpenSys/usr/bin/touch ' *CAT &LOG)
STRQSH CMD(&CMD)

/* Get Order file(s) */
/* Output Verbose (-vvv) Std Error (2) and Std Output (1) to Log File */

CHGVAR VAR(&SFTP) VALUE('/QOpenSys/usr/bin/sftp -b')
CHGVAR VAR(&CMD) VALUE(&SFTP *BCAT +
'/home/YOURUSER/sftpget.txt +
YOURUSER@104.130.246.115 > ' *TCAT &LOG +
*BCAT '2>&1')

STRQSH CMD(&CMD)

RCVMSG MSGTYPE(*COMP) MSGDTA(&MSGDTA) MSGID(&MSGID)
IF COND(&MSGID *NE 'QSH0005' *OR %BIN(&MSGDTA) +
*NE 0) THEN(DO)
SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA('SFTP +
script failed!') MSGTYPE(*ESCAPE)
ENDDO

/* Email SFTP Log to NYR Distribution List */
CHGVAR VAR(&SUBJ) VALUE('Get NYR Orders SFTP Log')
CHGVAR VAR(&STMF) VALUE(&LOG)
CHGVAR VAR(&TOADDR) VALUE('*067_IMPORT')
CHGVAR VAR(&CCADDR) VALUE(' ')
CHGVAR VAR(&MSG) VALUE('*ATT')
CHGVAR VAR(&BDYCNT) VALUE('text/plain')
CALLPRC PRC('Eml_StmfCL') PARM(('001TBF') +
(&SUBJ) (&STMF) (&TOADDR) (&CCADDR) +
(&MSG) (&BDYCNT)) +
RTNVAL(&ERRID)

DLTOVR FILE(*ALL)

END: ENDPGM

-----Original Message-----
From: MIDRANGE-L<midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of DEnglander--- via MIDRANGE-L
Sent: Tuesday, November 29, 2022 2:17 PM
To:midrange-l@xxxxxxxxxxxxxxxxxx
Cc:DEnglander@xxxxxxxxxxxxxxx
Subject: [EXTERNAL] SFTP examples

Does anyone have an example (or know of a URL where I can find an example) of using SFTP?

I need to have SFTP executed in a CL [or RPG] program that is submitted to Batch. That program will need to sign on to the remote SFTP server, execute the LS command on a specific folder, and then place the contents of the LS command into a file on the IFS.

My credentials are correct because I have another SFTP process that sends our IFS files to the same remote server, and it works fine [it does not create any logging/listing file but I would like it to]. I would like to capture the whole back and forth session between the two systems, and most importantly, the contents of the folder.

Any ideas?

Thank you,

Doug


"CONFIDENTIALITY NOTICE: This e-mail transmission (and/or the attachments accompanying it) contain confidential information belonging to the sender. The information is intended only for the use of the intended recipient. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of the information is strictly prohibited. Any unauthorized interception of this transmission is illegal under the law. If you have received this transmission in error, please promptly notify the sender by reply e-mail, and then destroy all copies of the transmission."
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email:MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:https://lists.midrange.com/mailman/listinfo/midrange-l
or email:MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives athttps://archive.midrange.com/midrange-l.

Please contactsupport@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link:https://amazon.midrange.com [CAUTION! This email originated outside of the organization. Please do not open attachments or click links from an unknown or suspicious origin.]



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.