*程序逻辑结构
*1. 查询FTP链接配置信息表获取源FTP及目标FTP登陆信息
*2. 建立源系统FTP链接
*3. 将源FTP服务器传输编码方式转换为ASCII
*4. 建立目标系统FTP链接
*5. 将目标FTP服务器传输编码方式转换为ASCII
*6. 将传输文件列表中源FTP目录下的源文件名重命名
*7. 关闭源FTP链接
*8. 关闭目标FTP链接
*9. 关闭RFC远程链接
配置表
参数
定义
查询获取登录信息
建立链接
转码
将传输文件列表中源FTP目录下的源文件名重命名
关闭源 链接
代码:
function zlm_frpmt_ftp_rename.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_SOURCE_NAME) TYPE CHAR50
*" REFERENCE(I_NEW_NAME) TYPE CHAR40
*" REFERENCE(I_DES_NAME) TYPE CHAR100
*" REFERENCE(I_DEST) TYPE CHAR10 OPTIONAL
*" EXCEPTIONS
*" FILE_IS_NOT_FOUND
*" FTP_CONNECT_FAILD
*" FTP_CHANGE_CODE_FAILD
*" FTP_CLOSE_FAILD
*" CAN_NOT_GET_CONNECTION_INFOR
*" FTP_RUN_RENAME_COMMAND_FAILD
*"----------------------------------------------------------------------
*程序逻辑结构
*1. 查询FTP链接配置信息表获取源FTP及目标FTP登陆信息
*2. 建立源系统FTP链接
*3. 将源FTP服务器传输编码方式转换为ASCII
*4. 建立目标系统FTP链接
*5. 将目标FTP服务器传输编码方式转换为ASCII
*6. 将传输文件列表中源FTP目录下的源文件名重命名
*7. 关闭源FTP链接
*8. 关闭目标FTP链接
*9. 关闭RFC远程链接
*-----------------------------------------------------------------------
**************************工作区声明区域********************************
types: begin of text,
line(120) type c,
end of text.
data:
l_wa_login type zlm_login_detail. "FTP登陆信息配置结构
* l_wa_file_list TYPE zlm_file_list. "传输文件结构
***************************内表声明区域*********************************
data:
l_tab_result type table of text with header line. "返回文本
***************************变量声明区域*********************************
data:
l_handle_s type i, "源FTP连接句柄
l_handle_d type i, "目标FTP连接句柄
l_dest type zlm_dest,
l_str_length type i, "密码长度
l_password(30) type c. "密码
data:
l_ftp_command(500) type c, "ftp命令
l_file_dir type string,
l_source_name type string, "源文件名
l_new_name type string. "新文件名
***************************常量声明区域*********************************
constants:
con_ftp_command_rename(6) type c value 'rename',
con_ascii(5) type c value 'ascii'.
******************************程序逻辑区域******************************
*"---------------------------------------------------------------------*
*" 1. 查询FTP链接配置信息表获取源FTP及目标FTP登陆信息
*"---------------------------------------------------------------------*
if i_dest is initial. "如果输入参数不为空值
l_dest = 'SAPFTPA'.
else.
l_dest = i_dest.
endif.
select single * from zlm_login_detail into l_wa_login
where dest = l_dest.
if sy-subrc 0.
raise can_not_get_connection_infor.
endif.
*"---------------------------------------------------------------------*
*" 2. 建立源系统FTP链接
*"---------------------------------------------------------------------*
l_str_length = strlen( l_wa_login-s_password ).
call function 'HTTP_SCRAMBLE'
exporting
source = l_wa_login-s_password "密码
sourcelen = l_str_length "长度
key = l_key "关键字
importing
destination = l_password. "密码
call function 'FTP_CONNECT'
exporting
user = l_wa_login-s_username "用户名
password = l_password "密码
host = l_wa_login-s_hostip "IP地址
rfc_destination = l_wa_login-dest "RFC逻辑目标
importing
handle = l_handle_s "源FTP连接句柄
exceptions
not_connected = 1.
if sy-subrc 0.
raise ftp_connect_faild.
endif.
*"---------------------------------------------------------------------*
*" 3. 将源FTP服务器传输编码方式转换为ASCII
*"---------------------------------------------------------------------*
call function 'FTP_COMMAND'
exporting
handle = l_handle_s "源FTP连接句柄
command = con_ascii "编码方式
tables
data = l_tab_result "返回文本
exceptions
others = 1.
if sy-subrc 0.
raise ftp_change_code_faild.
endif.
*"---------------------------------------------------------------------*
*" 4. 建立目标系统FTP链接
*"---------------------------------------------------------------------*
l_str_length = strlen( l_wa_login-p_password ).
call function 'HTTP_SCRAMBLE'
exporting
source = l_wa_login-p_password "密码
sourcelen = l_str_length "长度
key = l_key "关键字
importing
destination = l_password. "密码
call function 'FTP_CONNECT'
exporting
user = l_wa_login-p_username "用户名
password = l_password "密码
host = l_wa_login-p_hostip "IP地址
rfc_destination = l_wa_login-dest "RFC逻辑目标
importing
handle = l_handle_d "目标FTP连接句柄
exceptions
not_connected = 1.
if sy-subrc 0.
raise ftp_connect_faild.
endif.
*"---------------------------------------------------------------------*
*" 5. 将目标FTP服务器传输编码方式转换为ASCII
*"---------------------------------------------------------------------*
call function 'FTP_COMMAND'
exporting
handle = l_handle_d "目标FTP连接句柄
command = con_ascii "编码方式
tables
data = l_tab_result "返回文本
exceptions
others = 1.
if sy-subrc 0.
raise ftp_change_code_faild.
endif.
*"---------------------------------------------------------------------*
*" 6. 将传输文件列表中源FTP目录下的源文件名重命名
*"---------------------------------------------------------------------*
* 读取FTP上文件路径
select single des_addr into l_file_dir
from zftp_config
where des_name = i_des_name.
if sy-subrc 0.
raise file_is_not_found.
endif.
* 拼接源文件全路径
concatenate l_file_dir
i_source_name into l_source_name.
* 拼接新文件全路径
concatenate l_file_dir
i_new_name into l_new_name.
* 拼接ftp_command文件重命名命令
concatenate con_ftp_command_rename
l_source_name
l_new_name
into l_ftp_command
separated by space.
* 启动FTP命令
call function 'FTP_COMMAND'
exporting
handle = l_handle_d "目标FTP连接句柄
command = l_ftp_command "编码方式
tables
data = l_tab_result "返回文本
exceptions
others = 1.
if sy-subrc 0.
raise ftp_run_rename_command_faild.
endif.
*"---------------------------------------------------------------------*
*" 7. 关闭源FTP链接
*"---------------------------------------------------------------------*
call function 'FTP_DISCONNECT'
exporting
handle = l_handle_s. "源FTP连接句柄
*"---------------------------------------------------------------------*
*" 8. 关闭目标FTP链接
*"---------------------------------------------------------------------*
call function 'FTP_DISCONNECT'
exporting
handle = l_handle_d. "目标FTP连接句柄
*"---------------------------------------------------------------------*
*" 9. 关闭RFC远程链接
*"---------------------------------------------------------------------*
call function 'RFC_CONNECTION_CLOSE'
exporting
destination = l_dest "RFC远程连接
exceptions
others = 1.
if sy-subrc 0.
raise ftp_close_faild.
endif.
endfunction.
觉得有用请点 右下角 在看。
原创不易,谢谢支持~
领取专属 10元无门槛券
私享最新 技术干货