Skip to Content
avatar image
Former Member

How can I read a content folder from FTP to SAP?

This is the code I used:

"

DATA: w_cmd(40) TYPE c,
it_cmdout TYPE STANDARD TABLE OF x_cmdout.

DESCRIBE TABLE t_file LINES blob_length.
blob_length = blob_length * 80.

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

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

* connect
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = user
password = s_pwd
host = host
rfc_destination = 'SAPFTPA'
IMPORTING
handle = hdl.

" change directory
IF p_dir IS NOT INITIAL.

CONCATENATE 'cd' p_dir INTO w_cmd SEPARATED BY space.

CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = w_cmd
compress = 'N'
TABLES
data = it_cmdout
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4

"

Now I'm into the selected folder, but how can I red the content? In the folder there are a lot of PDF. I have to read the file name of these PDFs.

Thanks a lot,

Nicola

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Oct 19, 2016 at 11:06 AM

    Hi

    U need to use the command DIR in ordert to scan the directory by function FTP_COMMAND, so as you're doing for the command cd

    The list of the files will be placed in DATA

    Max

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 19, 2016 at 12:05 PM

    FTP command "DIR".

    CALL FUNCTION 'FTP_COMMAND'

    EXPORTING
    handle = gv_handle
    command = 'dir'
    TABLES
    data = gt_pdf
    EXCEPTIONS
    tcpip_error = 1
    command_error = 2
    data_error = 3
    OTHERS = 4.

    Then loop through the table "gt_pdf".

    LOOP AT gt_pdf INTO gs_pdf FROM 4 TO gv_tablelength. - Find the table length and you will need to cut off the time and date from the file names in the table.

    gs_pdf-line = gs_pdf-line+39(90).

    CONDENSE gs_pdf-line NO-GAPS.

    APPEND gs_pdf TO gt_pdf_new

    CLEAR:gs_pdf


    ENDLOOP.

    Then loop at gt_pdf_new and import each file using, CALL FUNCTION 'FTP_SERVER_TO_R3' .

    Add comment
    10|10000 characters needed characters exceeded