READ FILE FROM FTP SERVER

In this program, we connect a ftp server and read file to itab.

*&———————————————————————*

*& Report  ZAYKUT_TEST

*&

*&———————————————————————*

*&

*&   TEST FTP

*&———————————————————————*

REPORT zaykut_test.

DATA :

ftp_handle       TYPE i,

ftp_rfc_dest_aux LIKE rfcdesrfcdest VALUE ‘SAPFTPA’,

ftp_command(120TYPE c,

ftp_result TYPE sdoki_ftp_result_t,

pwd(30TYPE c ,

key TYPE i VALUE 26101957,

slen TYPE i.

pwd ‘Gt675F54’.

SET EXTENDED CHECK OFF.

slen strlenpwd ).

CALL FUNCTION ‘HTTP_SCRAMBLE’

  EXPORTING

    source      pwd

    sourcelen   slen

    key         key

  IMPORTING

    destination pwd.

CALL FUNCTION ‘FTP_CONNECT’

  EXPORTING

    user            ‘userftp’

    password        pwd

    host            FTP.**********.COM.TR

    rfc_destination ftp_rfc_dest_aux

  IMPORTING

    handle          ftp_handle

  EXCEPTIONS

    not_connected   1

    OTHERS          2.

CONCATENATE ‘cd’ ‘\FILES\SAP\TEST’

               INTO ftp_command SEPARATED BY space.

CALL FUNCTION ‘FTP_COMMAND’

  EXPORTING

    handle        ftp_handle

    command       ftp_command

  TABLES

    data          ftp_result

  EXCEPTIONS

    tcpip_error   1

    command_error 2

    data_error    3.

*CLEAR : ftp_result[].

*Merchant-20150917-161638.xls

DATABEGIN OF itab_tmp OCCURS 1,

        line(600)             ,

      END OF itab_tmp       .

 CALL FUNCTION ‘FTP_SERVER_TO_R3’

        EXPORTING

          handle         ftp_handle

          fname          ‘Merchant-20150917-161638.xls’“result-line+56(44)

          character_mode ‘X’

        TABLES

          text           itab_tmp

        EXCEPTIONS

          tcpip_error    1

          command_error  2

          data_error     3

          OTHERS         4.

CALL FUNCTION ‘FTP_DISCONNECT’

  EXPORTING

    handle ftp_handle

  EXCEPTIONS

    OTHERS 1.

CALL FUNCTION ‘RFC_CONNECTION_CLOSE’

  EXPORTING

    destination ftp_rfc_dest_aux

  EXCEPTIONS

    OTHERS      1.

One thought on “READ FILE FROM FTP SERVER

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s