Skip to Content
author's profile photo Former Member
Former Member

Reading and deleting files from ftp server

Dear Experts,


I want to read a file from the ftp server and want to delete it from the server after reading it.
I know only the folder in which this will contain for example "/from_X"


The files in the folder have the following naming convention :
ddmmyyyyhhmm.txt which is date (first 8 digits) and last 4 digits are time in (hhmm).

Want to read each file(the oldest first and the latest last).After reading each file I want to delete it also from the server.

I want to use the Functionmodule "FTP_SERVER_TO_R3" for this purpose.

In the wrk_file,we have to give the file name as well here apart from the folder,but as I said I dont know the filename.

How should I go about it to get the list of files from the folder and delete it.

wrk_file = '/from_X'.

CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = w_hdl
fname = wrk_file
character_mode = 'X'
* IMPORTING
* BLOB_LENGTH =
TABLES
text = text_tab
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.

Any pointers are welcome.

Thanks
K

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 21, 2012 at 07:06 PM

    First get all the files from the FTP file directorry using the followimg code:

    DATA: filelist TYPE STANDARD TABLE OF sdokpath,

    dirlist TYPE STANDARD TABLE OF sdokpath,

    w_filelist TYPE sdokpath,

    w_path LIKE p_file,

    w_dest LIKE p_dest,

    w_leng TYPE i.

    DATA: filelists TYPE STANDARD TABLE OF emg_fileinfo,

    w_filelists TYPE emg_fileinfo.

    DATA: w_servdir LIKE temfile-dirname.

    DATA: w_dir LIKE epsf-epsdirnam,

    w_file LIKE epsf-epsfilnam.

    w_leng = STRLEN( p_file ) - 1.

    IF p_file+w_leng(1) NE '\'.

    CONCATENATE p_file

    '\'

    INTO p_file.

    ENDIF.

    w_servdir = p_file(75).

    CALL FUNCTION 'ISU_M_GET_FILES_OF_DIR'

    EXPORTING

    x_path = w_servdir

    * X_APPEND = ' '

    * X_DISPLAY = ' '

    * IMPORTING

    * Y_FILEINFO =

    TABLES

    xy_filetab = filelists

    EXCEPTIONS

    no_start = 1

    no_next = 2

    no_finish = 3

    general_error = 4

    OTHERS = 5

    .

    IF sy-subrc <> 0.

    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    IF p_email IS NOT INITIAL.

    PERFORM f_begin_mail TABLES itab_objtxt.

    ENDIF.

    MOVE p_file TO w_path.

    w_leng = STRLEN( p_dest ) - 1.

    LOOP AT filelists

    INTO w_filelists.

    REFRESH:itab_upload.

    CLEAR: itab_upload,

    p_file,

    g_error.

    MOVE: w_path TO p_file,

    w_dest TO p_dest.

    CONCATENATE p_file

    w_filelists-name

    INTO p_file.

    MOVE p_file TO g_source.

    CONDENSE p_file.

    CONDENSE p_dest.

    g_dest = p_dest.

    g_source = p_file.

    OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

    IF sy-subrc EQ 0.

    DO.

    READ DATASET p_file INTO itab_upload.

    IF sy-subrc NE 0.

    EXIT.

    ELSE.

    APPEND itab_upload.

    CLEAR itab_upload.

    ENDIF.

    ENDDO.

    ENDIF.

    CLOSE DATASET p_file.

    ENDLOOP.

    Delete DATASET P_file.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.