|
/* 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 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.