*&---------------------------------------------------------------------*
*& Report ZHCM_UTILS_FTP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZHCM_UTILS_FTP.
*&---------------------------------------------------------------------*
DATA user(30) TYPE c VALUE 'FTP_USER'.
DATA pass(30) TYPE c VALUE 'FTP_PASS'.
DATA host(64) TYPE c VALUE 'SERVER.FTP.cl'. "'10.1.32.255'.
DATA dest TYPE rfcdest VALUE 'SAPFTPA'.
DATA hand TYPE i.
DATA erro LIKE sy-subrc.
*
DATA: BEGIN OF it_text OCCURS 0,
column1(10) TYPE c VALUE '1234567890', "L01
column2(10) TYPE c VALUE 'abcdeFGHIJ', "L02
column3(10) TYPE c VALUE 'Ñ;()#', "L03
END OF it_text.
*
BREAK-POINT.
*
PERFORM http_scramble CHANGING pass.
PERFORM ftp_connect USING user pass host dest hand CHANGING erro.
check erro is INITIAL.
*
append it_text.
append it_text.
append it_text.
*
PERFORM ftp_r3_to_server TABLES it_text USING hand CHANGING erro.
*
PERFORM ftp_disconnect USING hand.
PERFORM rfc_connection_close USING dest CHANGING erro.
*
*&---------------------------------------------------------------------*
FORM http_scramble CHANGING p_pass.
*
DATA leng TYPE i.
data pwd_(30) type c.
DATA key_ type i value 26101957.
*
leng = strlen( p_pass ).
*
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
source = p_pass
sourcelen = leng
key = key_
IMPORTING
DESTINATION = pwd_.
*
p_pass = pwd_.
*
ENDFORM.
*&---------------------------------------------------------------------*
FORM ftp_connect USING p_user p_pass p_host p_dest p_hand
CHANGING o_subrc.
*
CLEAR o_subrc.
CHECK p_user IS NOT INITIAL.
CHECK p_pass IS NOT INITIAL.
CHECK p_host IS NOT INITIAL.
CHECK p_dest IS NOT INITIAL.
* CHECK p_hand IS NOT INITIAL.
*
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = p_user
password = p_pass
* ACCOUNT =
host = p_host
rfc_destination = p_dest
* GATEWAY_USER =
* GATEWAY_PASSWORD =
* GATEWAY_HOST =
IMPORTING
handle = p_hand
EXCEPTIONS
not_connected = 1
OTHERS = 2.
IF ( sy-subrc <> 0 ).
o_subrc = sy-subrc.
ENDIF.
*
ENDFORM.
*&----------------------------------------------------------------------
FORM ftp_r3_to_server TABLES t_table USING p_hand CHANGING o_subrc.
*
CLEAR o_subrc.
CHECK p_hand IS NOT INITIAL.
*
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = p_hand
fname = 'aaa.txt'
* BLOB_LENGTH =
character_mode = 'X' "add
TABLES
* BLOB =
text = t_table "Data
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
IF ( sy-subrc <> 0 ).
o_subrc = sy-subrc.
ENDIF.
*
ENDFORM.
*&---------------------------------------------------------------------*
FORM ftp_disconnect USING p_hand.
*
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = p_hand.
*
ENDFORM.
*&----------------------------------------------------------------------
FORM rfc_connection_close USING p_dest CHANGING o_subrc.
*
CLEAR o_subrc.
CHECK p_dest IS NOT INITIAL.
*
CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = p_dest
* TASKNAME =
EXCEPTIONS
destination_not_open = 1
OTHERS = 2.
IF ( sy-subrc <> 0 ).
o_subrc = sy-subrc.
ENDIF.
*
ENDFORM.
*&---------------------------------------------------------------------*