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 rfcdes–rfcdest VALUE ‘SAPFTPA’,
ftp_command(120) TYPE c,
ftp_result TYPE sdoki_ftp_result_t,
pwd(30) TYPE c ,
key TYPE i VALUE 26101957,
slen TYPE i.
pwd = ‘Gt675F54’.
SET EXTENDED CHECK OFF.
slen = strlen( pwd ).
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
DATA: BEGIN 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.
Good job man! You are the best!
LikeLike