在测试连接FTP得时候,首先需要。IP地址,端口在配置表存在。如果不在,写入一条。
SELECT SINGLE *
FROM sapftp_servers INTO @DATA(ls_ftpserver)
WHERE ftp_server_name = @ps_zep0021-ftp_server_name
AND ftp_server_port = @ps_zep0021-ftp_server_port.
IF sy-subrc <> 0.
ls_ftpserver-ftp_server_name = ps_zep0021-ftp_server_name.
ls_ftpserver-ftp_server_port = ps_zep0021-ftp_server_port.
ls_ftpserver-description = ‘SAPFTPA’.
MODIFY sapftp_servers FROM ls_ftpserver .
COMMIT WORK AND WAIT.
ENDIF.
-
连接ftp服务器
CALL FUNCTION ‘FTP_CONNECT’
EXPORTING
user = ps_zep0021-ftp_usrname
password = l_pwd
host = lv_host_port
rfc_destination = lv_rfcdest "dest
IMPORTING
handle = l_hdl. "连接的句柄
然后再执行查询语句,比如:CLEAR l_nofile_f. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = l_hdl command = 'nlist /' " compress = l_compress TABLES data = lt_result.
发现总是超时。
是需要设置FTP服务器得模式。设置后就正常了。
CALL FUNCTION ‘FTP_COMMAND’
EXPORTING
handle = l_hdl
command = ‘set passive on’
TABLES
data = lt_result
EXCEPTIONS
command_error = 1
tcpip_error = 2.