Execute SFTP from batch PGM

20 pts.
Tags:
PGM
SFTP
I need to execute SFTP from batch PGM for certain accounts. How can I do that?


Software/Hardware used:
currently on 7.1 going to 7.3
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 18  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TheRealRaven
    And what problem are you running into?
    35,630 pointsBadges:
    report
  • ToddN2000
    Yes. Just set up some scripts that contain the FTP commands and you should not have an issue.. We do it here.
    Post your code and any errors if you cannot get it to work.
    We use a cl to login and send the file, logging all steps to a blank member.

    PGM        PARM(&LIBRARY)                                 
    DCL        VAR(&LIBRARY) TYPE(*CHAR) LEN(10)              
    CRTSAVF    FILE(QGPL/&LIBRARY)                            
                                                              
    SAVLIB     LIB(&LIBRARY) DEV(*SAVF) SAVF(QGPL/&LIBRARY) + 
                 TGTRLS(V7R1M0)                               
                                               
    /* ftp login and send */               
    OVRDBF     FILE(INPUT) TOFILE(MYLIB/QCLSRC) +         
                 MBR(FTPCODE)
    
    /* FTP log file  member type TXT */                                 
    OVRDBF     FILE(OUTPUT) TOFILE(MYLIB/QCLSRC) MBR(FTP) 
                                                              
    FTP        RMTSYS('10.10.10.1')                            
    DLTF       FILE(QGPL/&LIBRARY)                            
                                                              
    ENDPGM
    133,645 pointsBadges:
    report
  • ToddN2000
    in my example in the above post we use it to send a SAVLIB to a remote system on our network. You can drop the CRTSAVF and SAVLIB commands.  In the input member set you open, login, ftp command(S) then close and quit.
    133,645 pointsBadges:
    report
  • JDroke
    That does not look like SFTP to me.
    80 pointsBadges:
    report
  • ToddN2000
    That's the CL, the FTP commands are in the CL member FTPCODE. The FTP log process goes int the CL member FTP.
    I'll search our system again for a better example.

    There is some other front end stuff needed to be set up as Scott Klement goes into with a great PDF HERE

    For more on SFTP click HERE 

    And batch example HERE
    133,645 pointsBadges:
    report
  • Jpolep
    can u post the details of your ftp input file member 
    20 pointsBadges:
    report
  • ToddN2000
    input member looks something like this

    open S2034A3A              
    user ibm ibm               
    bin                        
    PUT qgpl/sndawv qgpl/sndawv
    close                      
    QUIT                       
    133,645 pointsBadges:
    report
  • ToddN2000
    IBM has a good write up on the process if it needs password authentication found HERE.
    133,645 pointsBadges:
    report
  • JDroke
    He asked about SFTP (SSH). Your example looks like plain vanilla FTP.
    80 pointsBadges:
    report
  • Splat
    You're going to have to establish your public/private keys & share the public key with your accounts.  

    I found this & this to be quite helpful. 

    I would strongly recommend you establish a profile purely for the purpose of creating the keys & executing the sFTP scripts.
    12,895 pointsBadges:
    report
  • ToddN2000
    @JDroke: Yeah that's what I get for not looking at it. I wrote the original SFTP code about 8 years ago before I left that department. Looks like new management changed the process, why I do not know. The links I provided give a good overview and plenty of sample code to get it up and running.  If problems arise, post your  errors and code and we will straighten it out.
    133,645 pointsBadges:
    report
  • JDroke
    Unless something has changed, SFTP requires QSHELL and won't be anything like what you posted.
    80 pointsBadges:
    report
  • ToddN2000
    @JDroke. even if my code from 8 years ago was not changed it may have still been outdated a bit due to new standards.

    You just need to set up some scripts in the IFS for logging in using the password then you can create a batch CL similar to this

    PGM  
    QSH CMD('/QOpenSys/etc/openssh_password_script.sh')
    QSH CMD('exec /QOpenSys/usr/bin/ksh -c "/home/sftpuser/batch_sftp_script.sh"')
    endpgm

    For a complete walk through of the SFTP process check out the IBM page HERE
    133,645 pointsBadges:
    report
  • Jpjawili
    ToddN2000, do you have steps on how to configure it so that SFTP can be done from IBM i IFS to a windows 7 or windows server? I have copied a couple of spooled files (reports) to the IBM i IFS and i wanted to SFTP all the reports (FTP MPUT maybe?) to a Windows box. does it have to be a windows server or can it be a windows 7 pc? Thank you.
    315 pointsBadges:
    report
  • Splat
    jpjawili, mput & mget work.  You just need to provide the full path.
    cd /[target folder]
    lcd /[source folder 1]/[source folder 1.1]/[source folder 1.1.1]/[source folder 1.1.1.1]
    mput *.txt
    quit
    12,895 pointsBadges:
    report
  • Jpjawili
    Thanks Splat. do i need QNTC configured for this since i am FTPing to a windows server from IBM i IFS? At the moment my PC and IBM i are on the same network domain. I am able to FTP from PC to iseries (PUT/GET) but i am unable to FTP from my iSeries to my PC. Pardon my network configuration ignorance. Thank you. 
    315 pointsBadges:
    report
  • Jpjawili
    Hi Splat, this is now ok. What i did was:
    1. on IBM i, CYSPLF *TOSTMF to an IFS folder, WCST(*PDF) parameter and file name appended with .pdf. 
    2. on NET USE command to map the IFS folder to a windows PC.  
    The PDF files (from the report / spooled files) are now accessible from Windows explorer. 
    315 pointsBadges:
    report
  • Splat
    Jpjawili, I've never concerned myself with QNTC for FTP (native) or sFTP. Your PC may not be set up as an FTP client which might explain your inability to FTP from the iSeries to it. Me, I just use Navigator to share out an IFS folder & then map a drive to it from my PC. Glad to know you've got things working.
    12,895 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: