12-11-2013 12:31 PM
Hi all,
Using FTP related function modules am able to create, read and delete the file in FTP server.
I need to read all files from FTP server dynamically without knowing name of file.
Thanks,
Maruthamuthu Subramani.
12-11-2013 12:36 PM
Hi,
you need to use the command 'dir' and then do a loop to the table, that's what i did. Check it
l_cmd = 'dir'.
PERFORM ftp_command USING l_cmd.
FORM ftp_command USING p_l_cmd TYPE char120.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = mi_handle
command = p_l_cmd
TABLES
data = mtab_data
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
ENDFORM. " FTP_COMMAND
Then:
LOOP AT mtab_data INTO wa_data.
CLEAR: l_process, l_extension.
* get file's name
l_fname = wa_data+39(50). " All depends on the carpets where the files are
......
endloop.
Regards
Miguel
12-11-2013 12:36 PM
Hi,
you need to use the command 'dir' and then do a loop to the table, that's what i did. Check it
l_cmd = 'dir'.
PERFORM ftp_command USING l_cmd.
FORM ftp_command USING p_l_cmd TYPE char120.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = mi_handle
command = p_l_cmd
TABLES
data = mtab_data
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
ENDFORM. " FTP_COMMAND
Then:
LOOP AT mtab_data INTO wa_data.
CLEAR: l_process, l_extension.
* get file's name
l_fname = wa_data+39(50). " All depends on the carpets where the files are
......
endloop.
Regards
Miguel
12-11-2013 1:16 PM
Hi Maruthamuthu,
You may refer sample code as below..
*First connect to server using credentials and get handle
lf_dest = p_dest.
IF lf_dest IS INITIAL.
lf_dest = 'SAPFTP'.
ENDIF.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = ftp_user
password = ftp_passwd
* ACCOUNT =
host = ftp_cname
rfc_destination = lf_dest
IMPORTING
handle = ftp_handle
EXCEPTIONS
not_connected = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
** go to the server path in the vault
CONCATENATE 'cd' path INTO ftpcommand SEPARATED BY ' '.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = ftp_handle
command = ftpcommand
TABLES
data = ftp_result
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
REFRESH ftp_result.
** list files in vault
ftpcommand = 'nlist'.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = ftp_handle
command = ftpcommand
* compress = compress
TABLES
data = ftp_result
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* ---------------------------------------------------------------------*
** disconnect FTP
* ---------------------------------------------------------------------*
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = ftp_handle.
12-12-2013 4:06 AM
Hi all,
Thanks for your quick reply.
I'll update other details, once completed the testing.
'DIR' command is working fine. But it returns all files with folders and messages. We had skipped unwanted line items from return table.
Regards,
Maruthamuthu