1, FTP介绍
FTP(File transfer protocol)是一种标准的网络协议,可以用于在互联网上传递文件。SAP系统中提供了一些标准函数,放在函数组SFTP中,
除此之外,sap还提供了一些demo程序:
RSFTP001 - SAPFTP Version (Current Version one is working on)
RSFTP002 - Execute FTP Command
RSFTP003 - FTP put / get Test
RSFTP004 - FTP Copy
RSFTP005 - SAPFTP check
RSFTP006 - FTP command list
RSFTP007 - Test FB:FTP_SERVER_TO_R3 / FTP_R3_TO_SERVER
RSFTP008 - Test FB:FTP_CLIENT_TO_R3 / FTP_R3_TO_CLIENT
RSFTP009 - Test FTP put with Verify
FTP相关一些术语:
USER : 连接FTP服务器的用户名.
PASSWORD : 密码
HOST : 需要连接的FTP服务器名字或者是ip地址
RFC Destination :RFC目标连接名字,通常是SAPFTP,可以通过SM59创建,选择TCP/IP连接
也可以通过执行SAP的标准程序RSFTP005,自动创建两个名为SAPFTP何SAPFTPA的TCP/IP的RFC连接。
HANDLE:可以用来执行FTP命令
2, 相关函数
在函数组SFTP中可以看到常用的一些函数,如下:
- 'HTTP_SCRAMBLE'
"获取加密密码 - 'FTP_CONNECT' "连接ftp服务器
- 'FTP_COMMAND'
"执行FTP命令 - 'FTP_SERVER_TO_R3'
"拷贝ftp服务器文件到r3 - 'FTP_COPY'
"拷贝文件到指定位置 - 'FTP_DISCONNECT' "断开FTP连接
- 'RFC_CONNECTION_CLOSE' "断开RFC链接
3, 例子程序
本例子实现向FTP服务器上传输文件,用到了put命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
REPORT ztest_ftp_sample. PARAMETERS: p_file TYPE char255 DEFAULT 'dummy.txt', p_host TYPE char64 DEFAULT 'scnftp.global.xxxx.com', p_folder TYPE char255 DEFAULT '/jobs_for_test/' LOWER CASE, p_uname TYPE char30 DEFAULT 'global/xxxxx' LOWER CASE, p_pwd TYPE char30 DEFAULT 'xxxxxxx' LOWER CASE. PARAMETERS: dest LIKE rfcdes-rfcdest DEFAULT 'SAPFTP', compress TYPE c DEFAULT 'N'. DATA: hdl TYPE i, key TYPE i VALUE 26101957, slen TYPE i, cmd(80) TYPE c. DATA: BEGIN OF result OCCURS 0, line(100) TYPE c, END OF result. slen = strlen( p_pwd ). * "获取加密密码 保存到P_PWD CALL FUNCTION 'HTTP_SCRAMBLE' EXPORTING source = p_pwd sourcelen = slen key = key IMPORTING destination = p_pwd. * 连接ftp服务器 CALL FUNCTION 'FTP_CONNECT' EXPORTING user = p_uname password = p_pwd host = p_host rfc_destination = dest IMPORTING handle = hdl. "连接的句柄 "执行FTP命令 CD 打开目标ftp的文件夹 "now open the target ftp folder concatenate 'cd' p_folder into cmd SEPARATED BY space. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = hdl command = cmd compress = compress TABLES data = result EXCEPTIONS command_error = 1 tcpip_error = 2. LOOP AT result. WRITE AT / result-line. ENDLOOP. REFRESH result. * 打开本地ftp文件夹 "now open the local ftp folder concatenate 'lcd' 'C:\TEMP\' into cmd SEPARATED BY space. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = hdl command = cmd compress = compress TABLES data = result EXCEPTIONS command_error = 1 tcpip_error = 2. LOOP AT result. WRITE AT / result-line. ENDLOOP. REFRESH result. * 将本地文件放到目标ftp文件夹中 CONCATENATE 'put ' p_file INTO cmd SEPARATED BY space. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = hdl command = cmd compress = compress TABLES data = result EXCEPTIONS command_error = 1 tcpip_error = 2. LOOP AT result. WRITE AT / result-line. ENDLOOP. REFRESH result. * 断开FTP连接 CALL FUNCTION 'FTP_DISCONNECT' EXPORTING handle = hdl. * 断开RFC链接 CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING destination = dest EXCEPTIONS OTHERS = 1. |
选择画面:
以上。
发表评论