Skip to Content
Technical Articles
Author's profile photo Biswajit sahoo

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

Assigned Tags

      15 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sandra Rossi
      Sandra Rossi

      Here, you are talking only about HTTP. I don't see where SFTP is. Can you explain?

      Author's profile photo Biswajit sahoo
      Biswajit sahoo
      Blog Post Author

      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.

      Author's profile photo Stevanic Artana
      Stevanic Artana

      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

      Author's profile photo Archie Hammer
      Archie Hammer

      Is there any additional information you can provide on accessing the SFTPs rest APIs? this could prove useful in the future when accessing SuccessFactors SFTP services.

      Author's profile photo Stevanic Artana
      Stevanic Artana

      SF uses Globalscape and here is the only REST API documentation I can find

      https://kb.globalscape.com/Knowledgebase/11297/EFT-HTTP-API-using-Curl

      Stev

      Author's profile photo Jim Fang
      Jim Fang

      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.

      Author's profile photo Sourav Das
      Sourav Das

      What should be the content type here?application/x-zip-compressed?

      Author's profile photo Biswajit sahoo
      Biswajit sahoo
      Blog Post Author

      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.

      Author's profile photo Marco Scalise
      Marco Scalise

      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

      Author's profile photo Stevanic Artana
      Stevanic Artana

      Have a look at sap note 2498454. SAP provides a sample program to do this.

       

      Stev

      Author's profile photo BALASUBRAMANIAN AP
      BALASUBRAMANIAN AP

      Short and sweet content...

      Author's profile photo Goutham Palicharla
      Goutham Palicharla

      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

      Author's profile photo Nilesh Panpaliya
      Nilesh Panpaliya

      Can you pl explain with screen shots

      Author's profile photo Daniele Sangiovanni
      Daniele Sangiovanni

      It doesn't work for me too ... yet I followed all the steps and details in note 2007916 and your post, and SM59 connection is tested correctly.

      Receiving HTTP ERROR when sending file: FILE_TEST.TXT, Code: 501, Reason: Not Implemented

       

      Can you pl explain with screen shots ?

      Author's profile photo Arnfried Dötsch
      Arnfried Dötsch

      Hello,
      ​I have a question to the Blog "Hows To Transfer Files Into SFTP using ABAP Program"

      ​What have I to maintain in SM59?
      ​Normally SFTP has an URL like sftp://....... and Port 22.

      ​But I think this is not the URL we have to put in SM59 RFC-Destination. If we try to do this we get an Error like
      "​Connect to sftp://myopenfactory.net:22 failed: NIEHOST_UNKNOWN(-2)"

      Can you someone help me​?

      ​Thanks