*&---------------------------------------------------------------------*
*& Form frm_trans_file_to_ftp
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_trans_file_to_ftp USING p_file
p_path.
DATA: user(30) TYPE c VALUE 'usname',
pwd(30) TYPE c VALUE 'password',
host(64) TYPE c VALUE 'ftpserver',
dest LIKE rfcdes-rfcdest VALUE 'SAPFTP',
compress TYPE c VALUE 'N'.
DATA: hdl TYPE i,
key TYPE i VALUE 26101957,
slen TYPE i.
DATA: BEGIN OF lt_commands OCCURS 0,
cmd(100) TYPE c,
END OF lt_commands.
DATA: BEGIN OF result OCCURS 0,
line(100) TYPE c,
END OF result.
SET EXTENDED CHECK OFF.
slen = strlen( pwd ).
AUTHORITY-CHECK OBJECT 'S_ADMI_FCD'
ID 'S_ADMI_FCD'
FIELD 'SFTP'.
IF sy-subrc <> 0.
MESSAGE 'no ftp authorization' TYPE 'I'.
EXIT.
ENDIF.
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
source = pwd
sourcelen = slen
key = key
IMPORTING
destination = pwd.
CONCATENATE 'lcd' p_path INTO lt_commands-cmd SEPARATED BY space.
APPEND lt_commands.
lt_commands-cmd = 'cd /文件夹/文件夹/'.
APPEND lt_commands.
TRANSLATE p_file TO LOWER CASE.
CONCATENATE 'put' p_file INTO lt_commands-cmd SEPARATED BY space.
APPEND lt_commands.
*该函数可以定义有网关时账户密码,一般公司内部访问时无此设置
DO 5 TIMES.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = user
password = pwd
host = host
rfc_destination = dest
IMPORTING
handle = hdl.
IF sy-subrc = 0.
EXIT.
ELSE.
WAIT UP TO 1 SECONDS.
ENDIF.
ENDDO.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
"INTO gs_out-msg
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
LOOP AT lt_commands.
IF lt_commands-cmd NE ' '.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = lt_commands-cmd
compress = compress
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
"INTO gs_out-msg
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = hdl.
ENDIF.
ENDFORM. " frm_trans_file_to_ftp
abap中,ftp上传文件demo
最新推荐文章于 2024-09-13 16:50:06 发布