IBM i Global

 View Only
Expand all | Collapse all

How to SFTP on IBM i

  • 1.  How to SFTP on IBM i

    Posted Thu August 17, 2023 04:59 PM

    Where can I find steps or documentation for setup, with examples, if possible, to do unattended SFTP on the IBM i?  We have a need to do SFTP instead of FTPS.  



    ------------------------------
    Amy Vozza
    ------------------------------


  • 2.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Thu August 17, 2023 10:13 PM

    Dear Amy

    One good place is Scott Klement's web site  https://www.scottklement.com/presentations/  and download this presentation :

    Here is an additional article on using SFTP inIBM i :  https://techchannel.com/SMB/12/2009/sftp-tips



    ------------------------------
    Education is not the learning of facts but the training of the mind to think. -- Albert Einstein.
    ------------------------------
    Satid S.
    ------------------------------



  • 3.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Fri August 18, 2023 02:16 AM

    Hi,

    Some links, to add to Satid's answer

    https://www.ibm.com/support/pages/configuring-ibm-i-sshd-server-use-public-key-authentication

    https://www.ibm.com/support/pages/example-batch-sftp-script

    https://www.ibm.com/support/pages/batch-sftp-download-example-using-password-authentication

    https://blog.faq400.com/en/system-administration-en/sftp-with-password-no-ssh-key-authentication-it/



    ------------------------------
    Fernando Plaza
    IBM i System Administrator
    CD INVEST
    MADRID
    ------------------------------



  • 4.  RE: How to SFTP on IBM i

    Posted Fri August 18, 2023 10:17 AM

    Thank you both for the information.  Those are a great help.  



    ------------------------------
    Amy Vozza
    ------------------------------



  • 5.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Mon August 21, 2023 03:25 PM

    And if you want a native application that runs on IBM i for SFTP..  Consider GoAnywhere..  https://www.fortra.com/product-lines/goanywhere#features

    This product is an application for exchanging IBM i data from DB2 or other sources too.

    Good luck

    Tom



    ------------------------------
    tom huntington
    ------------------------------



  • 6.  RE: How to SFTP on IBM i

    Posted Tue August 22, 2023 04:35 AM
    Hi ,

    Check with the remote site which ciphers they are using.
    Some are not supported on IBMi when using SFTP.
    Check the list in the link below : check the IBM version you are using.
    System TLS has infrastructure to support multiple cipher suites.


    regards

    Paul


     






  • 7.  RE: How to SFTP on IBM i

    Posted Tue August 22, 2023 01:25 PM

    I'm getting the error "Host key verification failed."  If I need to generate a different key type than what I did originally, will I need to delete my original keys first and then generate the new set?  For generating the key in PACE, is there a listing of type specification options for use in the command for that?  The options I've found are rsa, rsa1, dsa, or ecdsa.  



    ------------------------------
    Amy Vozza
    ------------------------------



  • 8.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Tue August 22, 2023 01:56 PM

    ecdsa or rsa (not rsa1).



    ------------------------------
    Jack Woehr
    IBM Champion 2021 - 2023
    IBM Qiskit Advocate
    ------------------------------



  • 9.  RE: How to SFTP on IBM i

    Posted Tue August 22, 2023 05:07 PM

    Good reference, thank you Satid:

    The same happens with IFS, a kind of NFS, that is also not very secure, but its security may be improved with sshfs, which is also natively supported on IBM i.



    ------------------------------
    Daniel Jose Lema Guanziroli
    ------------------------------



  • 10.  RE: How to SFTP on IBM i

    Posted Wed August 23, 2023 10:16 AM

    For SFTP on IBM i, do you need the public key of the partner when you are the client and they have the server?  One document I found mentions having the partner's public key in your known_hosts file. 



    ------------------------------
    Amy Vozza
    ------------------------------



  • 11.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Wed August 23, 2023 09:53 PM

    Dear Amy

    >>>> For SFTP on IBM i, do you need the public key of the partner when you are the client and they have the server?  One document I found mentions having the partner's public key in your known_hosts file.  <<<<

    Please refer to this IBM Technote for the answer :  Configuring the IBM i ssh, sftp, and scp clients to use public-key authentication at https://www.ibm.com/support/pages/configuring-ibm-i-ssh-sftp-and-scp-clients-use-public-key-authentication



    ------------------------------
    Education is not the learning of facts but the training of the mind to think. -- Albert Einstein.
    ------------------------------
    Satid S.
    ------------------------------



  • 12.  RE: How to SFTP on IBM i

    Posted Wed August 23, 2023 10:04 PM

    Thanks.  Yes, that is the document where I found mention of that.  Other documentation sources did not include that need.  When I asked our partner for their public key, they said I shouldn't need it.  So, I wanted to know if I was misunderstanding, and we didn't need it after all.  



    ------------------------------
    Amy Vozza
    ------------------------------



  • 13.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Wed August 23, 2023 10:31 PM

    >>>> When I asked our partner for their public key, they said I shouldn't need it.  <<<<

    According to the Technote, your partner is right in saying that you do not need the public key because you use private key. It's them who need your public key you produce for them.



    ------------------------------
    Education is not the learning of facts but the training of the mind to think. -- Albert Einstein.
    ------------------------------
    Satid S.
    ------------------------------



  • 14.  RE: How to SFTP on IBM i

    Posted Fri April 12, 2024 10:21 AM
    Edited by David Strawn Fri April 12, 2024 10:44 AM

    MOVED TO SEPERATE POST:

    how do you specify an email address as the user ID in the SFTP command?

    SFTP helpdesk@florenceco.org@(server name)



    ------------------------------
    David Strawn
    ------------------------------



  • 15.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Wed August 23, 2023 12:08 PM

    Daniel;

    These are commands to secure the IFS directories: 

    DSPAUT – Display Authority
    WRKAUT – Work with Authority
    CHGAUT – Change Authority
    CHGOWN – Change Directory Owner
    You can have both data and object authority to directories and their contents.  It can be as secure as any other NFS, unfortunately it is not always setup properly. Or it was setup 20 years ago.


    ------------------------------
    tom huntington
    ------------------------------



  • 16.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Wed August 23, 2023 01:10 PM

    If you're open to using something like Python, check out these examples:

    https://github.com/richardschoen/PythonSamples/tree/master/ibmi

    The two specific examples are:

    pysftpupload.py

    pysftpdownload.py

    pysftprmtcmd.py can be used to run remote commands as well.



    ------------------------------
    Richard Schoen
    ------------------------------



  • 17.  RE: How to SFTP on IBM i

    Posted Fri August 25, 2023 11:00 AM

    Another product to look at is LFTP. It can be easily scripted and integrated into a CL. And is is free. 



    ------------------------------
    Peter Langhammer
    ------------------------------



  • 18.  RE: How to SFTP on IBM i

    Posted Mon August 28, 2023 11:59 AM

    I threw this together(uses lftp) for getting PTF DVD files from IBM :

    getiptf/Get_i_PTF.sh at master · bdietz400/getiptf (github.com)



    ------------------------------
    Bryan Dietz
    ------------------------------



  • 19.  RE: How to SFTP on IBM i

    Posted Tue December 12, 2023 04:44 PM

    Hi Peter, 
    I'm trying to change ftp-scripts to SFTP using LFTP as it looks nice to use . 
    You have examples of using LFTP ?
    At this moment, the ftp-scripts are changing the input with example date and hour in the filenames that are ended. 

    Would be nice to know how to do this with LFTP ... I guess we need to create the file and push it to ifs and use it from there.
    Kinda new to this, so any help on LFTP and using open source Unix !
    Greetings 



    ------------------------------
    Ludo Neujens
    ------------------------------



  • 20.  RE: How to SFTP on IBM i

    Posted Tue December 12, 2023 05:09 PM

    Hi Ludo,
    I'll be happy to provide you with some examples. We use it in CL programs to notify partners about coming warehouse deliveries (something like WarehouseStockTransferShippingAdvice) via SFTP and for EDI894 via SFTP.

    Call the CL with parameters build the QSH command string and execute it...

    Works great for us and is reliable.

    Let me prepare some example code and then post it here...

    Today is too late for that. I get you something tomorrow.

    Peter



    ------------------------------
    Peter Langhammer
    ------------------------------



  • 21.  RE: How to SFTP on IBM i

    Posted Tue December 12, 2023 05:24 PM

    I've been working on a "better" way to get the files from IBM.

    i put the parts here GitHub - bdietz400/getiptf: Get PTF CD images from IBM fix central

    get_from_FIX_Central.sh

    getfrmfixc.clle 

    getfrmfix.cmd

    not much documentation, but should be easy to figure out.



    ------------------------------
    Bryan Dietz
    ------------------------------



  • 22.  RE: How to SFTP on IBM i

    Posted Thu December 14, 2023 11:17 AM

    Hi Ludo,

    in the attachments are 2 CL's
    NI001CS builds the filename and populates the file, once it is ready it goes into the IFS
    and NI004C does the LFTP via SFTP.
    I had some changes to LFTP config file,
    In /QOpenSysy/etc is config file lftp.conf


    auto-confirm true 
    use-quit true
    log:enabled tru
    log file"xxx/xxx_LFTP.txt"
    log:level9
    logfile/xfer /xxxx/xxx/xxxx_Transfer.log
    the _LFTP logfile is a very detailed debug level logfile
    the _Transfer.log has 1 line per transfer

    Install LFTP via IBM i Package Manager.

    I have several IBM i partitions, so I started developing and testing just to SFTP from 1 partition to another
    before trying with a real businesspartner...

    Hope that helps!

    Peter



    ------------------------------
    Peter Langhammer
    ------------------------------

    Attachment(s)

    txt
    NI004C.txt   4 KB 1 version
    txt
    NI001CS.txt   5 KB 1 version


  • 23.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Fri August 25, 2023 11:29 AM

    https://www.seidengroup.com/2022/12/27/automate-sftp-transfers-using-expect/



    ------------------------------
    Jack Woehr
    IBM Champion 2021 - 2023
    IBM Qiskit Advocate
    ------------------------------



  • 24.  RE: How to SFTP on IBM i

    IBM Champion
    Posted Wed December 13, 2023 08:50 AM

    Here is a nice blog on using GoAnywhere on IBM i.  This tool will support IBM i and any other platform or cloud server.  https://www.fortra.com/blog/10-ways-goanywhere-mft-can-improve-your-efficiency-ibm-i



    ------------------------------
    Tom Huntington
    ------------------------------



  • 25.  RE: How to SFTP on IBM i

    Posted Wed April 17, 2024 12:47 PM

    With the open PASE tools (yum), if ones want to avoid string script parsing as much as possible and need a robust solution with db usage, it is worth IMHO using a proper high level language given that SFTP and ODBC and error handling are usually decent (and useful in case of logging, auditing and faults). And invoke it from CL (using env vars or a db record).

    Usually the solution is even more compact and simple than a pure shell script.

    Anyway, given the pervasive and ubiquity requirements (like FTP in the past, and we got the command for it) in businesses, it would be nice if IBM considered to bring a standard CL/ILE solution for SFTP, usually basic operation like SENDFILE , RECEIVEFILE, LISTREMOTEDIR macro operations should be sufficient.

    Even maybe an SQL interface to it (like it is fashion nowadays for many services) with robust exception returning...



    ------------------------------
    --ft
    ------------------------------



  • 26.  RE: How to SFTP on IBM i

    Posted Mon May 13, 2024 08:52 AM

    I was trying to setup an SFTP access for IBMi where my IBMi would be acting as the host and an SAP server would be acting as a client.

    I did all these steps given in this link. Note: I wanted to give restricted access to the SFTP client so I had to use CHROOT to create a 'jailed root' for the user profile using which the SFTP will be initiated. 

    Everything else works fine, but when I initiate the connection, the connection gets closed in 5-6 seconds. 

    Please see the screenshot below.

    Note: The full access method given in the above link works fine. But I'm trying to setup the 'jailed root' method using CHROOT. 

    Could you please tell me what am I doing wrong?

    Regards,

    Ravi.



    ------------------------------
    Ravisankar Pandian
    ------------------------------



  • 27.  RE: How to SFTP on IBM i

    Posted Mon May 13, 2024 01:40 PM

    I usually add -vvv parameter (for maximum debug level logging) to the sftp command as a first step to any sftp comms triage effort. If you try that and share the output with us (it's going to be long), we could get better insight into the client side.



    ------------------------------
    Roman Chloupek
    ------------------------------



  • 28.  RE: How to SFTP on IBM i

    Posted Wed May 15, 2024 01:46 PM
    Hello Ravisankar,

    Since we did not get to see your output with -vvv parameter, I can only speculate that the handshake with the sshd is completed successfully, and the issue happens after sshd hands the session over to the sftp subsystem.

    The "chroot_setup.sh" log you shared with us shows that the sftp-server (the sftp subsystem handler) is dated Oct  6  2023, which is about the time IBM released OpenSSH-related security fixes. There is a chance that your particular version of sftp-server on your system already requires libcrypto.so.3 while older version of sftp-server required libcrypto.so.1.1.

    Unfortunately, it looks like IBM did not update "chroot_setup.sh" script to reflect the change. You may try to copy it manually to see what happens:

    CPY OBJ('/usr/lib/libcrypto.so.3') TODIR('<root_of_the_chrooted_environment>/usr/lib/') OWNER(*KEEP)

    ...so looking into your log, that would be something like:

    CPY OBJ('/usr/lib/libcrypto.so.3') TODIR('/QOpenSys/QIBM/UserData/SC1/OpenSSH/chroot/usr/lib/') OWNER(*KEEP)

    If that does not help, try to apply the latest PTFs (which you should do anyway). I just checked my sftp-server and it shows as February 16, 2024 (v7.3) or March 7, 2024 (v7.4), so you might not have the latest version on your system.

    Hope this helps.





  • 29.  RE: How to SFTP on IBM i

    Posted Mon May 13, 2024 09:27 PM

    Dear Ravisankar

    I'm confused. Do you use "Restricted Access" method described in your provided Github link?   If so, how do you encounter the problem when you already have those steps described in your link (which imply they should work)?    My guess is that one of those commands in the long list of preparation steps may have an error that you may overlook.  Do you ensure each command you run does not have an error returned by IBM i? 



    ------------------------------
    Satid S
    ------------------------------



  • 30.  RE: How to SFTP on IBM i

    Posted Tue May 14, 2024 04:40 AM
      |   view attached

    Hi Satid,

       Thank you for the reply.

    • Yes, I did use the "Restricted Access Method" described in my GitHub repo.
    • The steps given in the "Restricted Access Method" are actually from the IBMi's documentation Using chroot on the IBM i to Restrict ssh, sftp, and scp to Specific Directories.
    • I also checked the chroot_config.log and found no possible issues there. Attached the same for your reference.
    • I am also confused because, all the steps given on the IBMi documentation have been completed successfully. But still the connection is getting closed in 4-5 seconds.
    • By looking at the screenshot below, I could see that the SFTP actually got initiated and due to some configuration/network issue the connection is closed. Notice the message "ECDSA key fingerprint is SHA256:xxxxx" --> does that mean the SFTP got connected at first?
    • Please let me know your thoughts on this.

    Regards,



    ------------------------------
    Ravisankar Pandian
    ------------------------------

    Attachment(s)

    log
    chroot_config.log   26 KB 1 version