【ABAP】FTP Program

sapkitty發表於2013-04-11

ABAP FTP Program

[@more@]

-------------------------------------------------------------------------------

DATA: l_hdl TYPE i,
l_key TYPE i VALUE 26101957,
l_slen TYPE i,
l_compress TYPE c VALUE 'N',
l_ftp_filename(80) TYPE c,
l_cmd(80) TYPE c .

DATA: ls_result TYPE ts_cmd_result,
lt_result LIKE TABLE OF ls_result.

l_slen = STRLEN( pwd ).

CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = pwd
sourcelen = l_slen
key = l_key
IMPORTING
destination = pwd.

CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = user
password = pwd
host = host
rfc_destination = dest
IMPORTING
handle = l_hdl.

*enter directory
CONCATENATE 'cd' pa_filea INTO l_cmd SEPARATED BY space.
PERFORM exec_command USING l_hdl l_cmd l_compress CHANGING lt_result.

"CONCATENATE host pa_filea INTO l_fname.
PERFORM filename_timestamp CHANGING l_ftp_filename.

CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = l_hdl
fname = l_ftp_filename
character_mode = 'X'
TABLES
text = gt_record.

IF sy-subrc = 0.
MESSAGE s013.
ENDIF.

* Disconnect
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = l_hdl.

CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = dest
EXCEPTIONS
OTHERS = 1.

-------------------------------------------------------------------------------

FORM exec_command USING p_hdl
p_cmd
p_compress
CHANGING pt_result TYPE tt_cmd_result.

CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = p_hdl
command = p_cmd
compress = p_compress
TABLES
data = pt_result
EXCEPTIONS
command_error = 1
tcpip_error = 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.
ENDFORM. " EXEC_COMMAND

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8214011/viewspace-1060385/,如需轉載,請註明出處,否則將追究法律責任。

相關文章