Skip to Content
Technical Articles

How To Transfer Files Into SFTP using ABAP Program

Introduction to SFTP:

SFTP – Secure File Transfer Protocol

This creates an encrypted channel between SAP and the targeted system SFTP. In cloud environment most of the client follows this concept to store files in to SFTP from Integration perspective.

Usage:

While transferring files from SAP ECP ( Employee Central Payroll ) to any 3rd party vendor OR to any internal application , SAP has given this Secure File Transfer Protocol . Mostly used in ECP and SuccessFactors environment.

Brief recall of other file transfer techniques :

A. File transfer to SAP from local system using CL_GUI_FRONEND_SERVICES. Method: GUI_DOWNLOAD / GUI_UPLOAD.

B. File Transfer using LSMW.

C. File transfer to SAP Application Server ( AL11 ) using DATA SET concept .

Example:

OPEN DATASET Filename FOR access IN mode [position]
[os_addition]
[error handling] .

Steps To Transfer File From SAP To SFTP Using HTTP Connection:

Step 1: Step up HTTP RFC connection

Make sure there must be a RFC exist (check in SM59 under HTTP connection to External Server) Connection Type – ” G  ” (HTTP Connection to External Server) . In target host of technical settings provide the correct URL (This URL is to access SFTP server) .

Step 2: Create complete file name 

It must include your file destination and file name separated by “/ “.

Step 3: Write your ABAP code to make connection to RFC using CL_HTTP_CLIENT

Method: CREATE_BY_DESTINATION  – Here connection will be establish between SFTP and Backend ABAP Program .

Collect reference of IF_HTTP_CLIENT ( Ex. Ref_client type ref to IF_HTTP_CLIENT )

Step 4 : Set the URI ( Set the File Detail )

Class : CL_HTTP_UTILITY , Method : SET_REQUEST_URI – pass above received connection details with uri ( file name ).

Step 5 : Set Header Fields

Use Ref of IF_HTTP_CLIENT ( ref_client ) , Method : REQUEST  and SET_HEADER_FIELD

Parameters :

A . ~request_method : DELETE/PUT/GET ( Depending on requirement ).

B. ~server_protocal : HTTP/1.0

C. content_type : Pass the whole content in xstring format

Step 6: Put file in to SFTP

Use Ref of IF_HTTP_CLIENT ( ref_client ) , Method : SET_DATA

Step 7: Read file from SFTP

Use Ref of IF_HTTP_CLIENT ( ref_client ) , Method : GET_DATA

Step 8: send/receive via HTTP Sever

Use Ref of IF_HTTP_CLIENT ( ref_client ) , Method : SEND and Method : RECEIVE

Step 9: Close Connection 

Never forget to close your connection after successful response.

************************SHARE AND LEARN************************

9 Comments
You must be Logged on to comment or reply to a post.
    • Hello Sandra,

      The main objective is to transfer data from SAP to SFTP server using HTTP class .

      We can use CL_HTTP_CLIENT class / IF_HTTP_CLIENT interface in OO ABAP to transfer data from SAP to SFTP ( which is a secure server provided by SAP for cloud Application ).

      Thanks.

      • Hi Biswajit,

        SuccessFactors SFTP server happens to provide REST API in addition to SFTP service and you have used the REST API in your program. Not all SFTP servers provide REST API.

        Thank you for sharing regardless. Looking forward to more content.

         

        Regards,

        Stev

  • Hi Biswajit,

    Do you know how to get the file list under a specified folder? and do you know how to use a wildcard to get the files? e.g, *.xml will return all file suffixed with .xml, like file1.xml, file2. I’m asking this because I have a requirement that I don’t know the complete filename, what I know is the only folder path. Thanks.

    • Hey Surav,

      Content type indicates , which type of content you are going to store into SFTP depending on request method .

      If request method is put , then convert your complete data into xstring format and pass on that parameter .

      If request method is get , then you are going to receive the data in a xstring format and convert it as per your use .

      Thanks.

  • Hi Biswajit,

    Great blog post!

    I tried to get a CSV file from SuccessFactors SFTP using your instructions, but without success…

    Could you please specify your example a little bit more ?
    Maybe with coding and pictures?

    That would be really great!

    Regards,
    Marco

  • Hi Biswajit,

     

    Your content is very high level. I am not sure its going to help many as most will not be able to understand. I wish you could have put more details with an example and this would have been a great blog.

     

    Appreciate your work!!

     

    Thank you,

    Goutham