Hello ,

I am posting this blog to list out my findings of the possibility of Connecting to a server enabled with  SFTP from a Abap program.

I have been given this requirement from my company that i create a report and transfer it to a server which has been changed from normal FTP to SFTP.

In my previous blogs i have already listed the process of using Function Modules to transfer using normal FTP.

I hope this blog helps people understand the limitations of sap abap in using sftp

SAP ABAP has the Functionality to write/Read on FTP server, but there is no functionality in ABAP to read /Write on SFTP server. The code will not work with SFTP server .

 

Please refer to  SAP Note 795131 – FAQ: How to make Secure FTP communication with SAPFTP.

 

SAP recommendations

Sap’s recommendation to read/write to SFTP server is by using PI (Process Integration) solution.

Option 1

 

Server side scripting commands to write to SFTP server from SAP Application Server with the help of an open Source FTP client (WinSCP).I was able to write the script for this in a notepad .

code.

option batch abort

option confirm off

open sftp://username:password@192:192:192:192:9952   { where 192.192.192.192 is the server address and 9952 is the port number }

put F:\check.txt  { This is a local file i created that can be transferred to check the put statement}

close

exit

Note : If you want to test this code above please install WinSCP and open Winscp.com . Type the code step by step and you will connect and put the file.

The challenge here was that i replicate this using External Commands in SM69 in SAP .So i got to it but the issue here was our system needed some upgrades from a Basis point of view where enabling of External Commands was possible. This is how far i got .

Note : If any one who reads this blog has implemented External Commands from SAP to transfer SFTP please share .

Option 2

Secure File Transfer Protocol (SFTP) can be achieved using SSH (Secure Socket Shell

The flow of the data goes as follows:

  1. Firstly the SSH (client local/daemon local) is configured as per the Vendors instructions.
  2. The SSH client is installed to the client system while the SSH daemon is installed to the FTP server.
  3. The data is sent from SAPFTP to the local port of the SSH client and this makes the data secure (encrypts the data).
  4. Then the SSH client sends this data to the SSH server daemon which decrypts the data and forwards the data to the FTP server.

SSH can be configured for both Active and Passive mode of FTP communication.

Conclusion

There is no straight forward method to transfer to a SFTP server .

Thank you .

Please do post comments and feedback to help me improve my content.

To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. Nelis Lamprecht

    Option 3

    Use SCP to copy files from one server to another. You can setup SSH public key authentication between the two servers so no password is required but the connection is still secured. If the server you are copying to is Windows based you can use CYGWIN to run an SSH service.

    (0) 
  2. Jelena Perfiljeva

    Was hoping for found an easy solution, but I guess no such luck… But thanks anyway for sharing your findings!

    We’ve had to do an SFTP transfer for just one interface and came up with a very primitive solution of extracting the files to the SAP application server, as usual, and running a scheduled script outside of SAP to get the files and SFTP them. Our limitations were: 1) no in-house Basis support; 2) SAP server runs on Linux; 3) SFTP server was not ours; 4) it was a rather low-priority project, didn’t have much time to invest.

    We have no plans or desire or even a need to run PI, so it’d be very helpful if this was available in standard SAP, just like regular FTP.

    (0) 
    1. Samuli Kaski

      If you have control over both transport ends, you can configure a SSH tunnel and use plain FTP on top of it. No changes are required on the application layer.

      (1) 
      1. Jelena Perfiljeva

        Thanks, Samuli! Unfortunately in our case it was exactly the problem that we didn’t control the other end – they just gave us a login and we had to figure out how to get the files there.

        (0) 
          1. Jelena Perfiljeva

            We didn’t find anything much better. In another system we are running a script that does all the SFTP work as a step in the background job. It’s slightly better than running the script outside of SAP since any messages appear in the job log. But still a simpler solution, like for FTP, would be preferable.

            (0) 
              1. Jelena Perfiljeva

                I didn’t write the script so can’t do, sorry. The script language would be specific to your OS though and you could just look up the commands online. Or ask your Basis admin, they might have more information.

                (0) 

Leave a Reply