Application Development 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: 

Downloading excel file from FTP Server to Application Server

Former Member
0 Kudos

Hi,

I have to get data from an excel file available on FTP server into an Internal table.Can I use FTP_SERVER_TO_R3 to do so.

Please let me know if there are any function modules available to do this.

Thanks,

Prasuna.

2 REPLIES 2

Former Member
0 Kudos

Hi Gayatri,

To pick the data from the FTP server directly into an internal table can be achieved by using the function module FTP_SERVER_TO_R3.

Here pass the handle, filename on the FTP server and character mode (as X) and receive the contents in the table parameter text. The internal table will be a character type table (one field of type c). Now this table can be used for further processing as per requirement. Use of the function module FTP_R3_TO_SERVER would copy the contents from an internal table on the FTP server. Before calling this function module we may need to call the FTP_COMMAND and pass a command to change the path to the destination directory on the FTP server.

Hope this helps.

Regards,

Abhijeet

shaik_sajid
Active Contributor
0 Kudos

Dear Gayatri,

You can get the file from FTP to internal table...

I am sending you the code with inline comments ....Hope this will be helpful to you.

Data: lv_key           TYPE i VALUE 26101957.
Data: lv_password(30)  TYPE c.

  i_rfc_destination = 'SAPFTP'.

  lv_length = STRLEN( i_password ).

 CALL FUNCTION 'HTTP_SCRAMBLE'
    EXPORTING
      SOURCE      = i_password "give ftp server pwd
      sourcelen   = lv_length
      key         = lv_key
    IMPORTING
      destination = lv_password.

  CALL FUNCTION 'FTP_CONNECT'
    EXPORTING
      user            = i_user "give ftp user name
      password        = lv_password
      host            = i_host
      rfc_destination = i_rfc_destination 
    IMPORTING
      handle          = lv_ftp_handle
    EXCEPTIONS
      not_connected   = 1
      OTHERS          = 2.

    CONCATENATE 'cd' i_folder_path INTO lv_cmd SEPARATED BY space.
*i_folder path is the path in ftp server where file is  stored

    CALL FUNCTION 'FTP_COMMAND'
      EXPORTING
        handle        = lv_ftp_handle
        command       = lv_cmd
      TABLES
        data          = result
      EXCEPTIONS
        command_error = 1
        tcpip_error   = 2.

     lv_blob_length = 392.

     TRANSLATE i_filename TO LOWER CASE.

      CALL FUNCTION 'FTP_SERVER_TO_R3'
        EXPORTING
          handle      = lv_ftp_handle
          fname       = i_filename          "give required file name
        IMPORTING
          blob_length = lv_blob_length
        TABLES
          blob        = lt_dummy.

Regards

Sajid