Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to connect SFTP server through ABAP program

Former Member
0 Likes
22,567

Dear Friends,

we are creating a batch job and moving files from AL11 to a specific folder. we have to use SFTP for transferring data instead of FTP.

I seached a lot, but I am not getting solution for this implementation in ABAP

please provide a solution ASAP.

Thanks and regards,

Vinod

Dear Friends,

we are creating a batch job and moving files from AL11 to a specific folder. we have to use SFTP for transferring data instead of FTP.

I seached a lot, but I am not getting solution for this implementation in ABAP

please provide a solution ASAP.

Thanks and regards,

Vinod

7 REPLIES 7
Read only

former_member209818
Active Contributor
0 Likes
4,401

Hi Vinod,

As you mentioned, I think SAP do not provide a SFTP protocol connection. But it provides various FM to have a FTP connection. You can find related FMs in Func Group SFTP and can make use of those FMs in your Program.

I believe SFTP data transfer if supported by Latest SAP PI data communication. Check if you have any SAP PI/XI consultant in your Project

- Harshad

Read only

0 Likes
4,401

hello harshad,

                     what you mean to say is that it is not possible to implement SFTP in ABAP.

Thanks and regards,

vinod

Read only

Former Member
0 Likes
4,401

Have you tried FTP_CONNECT?

Thanks, Abhinab

Read only

0 Likes
4,401

hi abhinab,

               I need to use SFTP and not FTP?

Thanks,

vinod

Read only

SatheeshKumara1
Participant
0 Likes
4,401

Hi Vinod,

     It is possible check the below sample program......

-Satheesh

REPORT  zftp_backgroud_app.

DATA:BEGIN OF mtab_data OCCURS 0,
line(132) TYPE c,
END OF mtab_data.

DATA:l_host(64) TYPE c VALUE 'XXX.XXX.XXX.XXX',
       cmd(80) TYPE c,
       cmd1(80) TYPE c,
       compress(20) TYPE c ,
       cmd2(80) TYPE c,
       pwd(30) TYPE c,
       key TYPE i VALUE 26101957,
       slen TYPE i,
       mi_handle TYPE i.

pwd = 'password'.

cmd1 = 'put d:\test\test2.txt'.

cmd = 'ascii'.

cmd2 = 'cd /tmp'.

compress  = 'N'.

SET EXTENDED CHECK OFF.
slen = strlen( pwd ).

AUTHORITY-CHECK OBJECT 'S_ADMI_FCD'
          ID 'S_ADMI_FCD'
          FIELD 'SFTP'.
IF sy-subrc <> 0.
   MESSAGE 'no_authorization' TYPE 'E'.
   EXIT.
ENDIF.

CALL FUNCTION 'HTTP_SCRAMBLE'
   EXPORTING
     source      = pwd
     sourcelen   = slen
     key         = key
   IMPORTING
     destination = pwd.


CALL FUNCTION 'FTP_CONNECT'
   EXPORTING
     user            = 'root'
     password        = pwd
     host            = l_host
     rfc_destination = 'SAPFTPA' "'ZRFC_PV'  "'SAPHTTPA'
   IMPORTING
     handle          = mi_handle
   EXCEPTIONS
     not_connected   = 1
     OTHERS          = 2.



IF cmd2 NE ' '.
   CALL FUNCTION 'FTP_COMMAND'
     EXPORTING
       handle        = mi_handle
       command       = cmd2
       compress      = compress
     TABLES
       data          = mtab_data
     EXCEPTIONS
       tcpip_error   = 1
       command_error = 2
       data_error    = 3
       OTHERS        = 4.
   LOOP AT mtab_data.
*    WRITE AT / mtab_data.
   ENDLOOP.
   REFRESH mtab_data.
ENDIF.

IF cmd NE ' '.
   CALL FUNCTION 'FTP_COMMAND'
     EXPORTING
       handle        = mi_handle
       command       = cmd
     TABLES
       data          = mtab_data
     EXCEPTIONS
       tcpip_error   = 1
       command_error = 2
       data_error    = 3
       OTHERS        = 4.
   LOOP AT mtab_data.
*    WRITE AT / mtab_data.
   ENDLOOP.
   REFRESH mtab_data.
ENDIF.

IF cmd1 NE ' '.
   CALL FUNCTION 'FTP_COMMAND'
     EXPORTING
       handle        = mi_handle
       command       = cmd1
     TABLES
       data          = mtab_data
     EXCEPTIONS
       tcpip_error   = 1
       command_error = 2
       data_error    = 3
       OTHERS        = 4.
   LOOP AT mtab_data.
*    WRITE AT / mtab_data.
   ENDLOOP.
   REFRESH mtab_data.
ENDIF.


CALL FUNCTION 'FTP_DISCONNECT'
   EXPORTING
     handle = mi_handle
   EXCEPTIONS
     OTHERS = 1.

CALL FUNCTION 'RFC_CONNECTION_CLOSE'
   EXPORTING
     destination 'SAPHTTPA'  "'SAPFTP' " 'ZRFC_PV'  "'SAPHTTPA'
   EXCEPTIONS
     OTHERS      = 1.

Read only

0 Likes
4,401

Hi Satheesh,

Here also you are using FTP protocol only. Not the SFTP protocol. It seems you are only trying to check if user has some SFTP authorization. But data is not sent thru SFTP protocol. Ultimately you are sending the data using FTP protocol only.

As far as I remember, SAP has not suported SFTP protocol. But check if any new versions got that support.

- Harshad

Read only

UweFetzer_se38
Active Contributor
4,401

It's still not possible to transfer files thru SFTP using plain ABAP. See SAP note 795131.

See also: