SAP系統中連接FTP服務器需要配置表SAPFTP_SERVERS,在這個表中添加ftp服務器及端口,然後使用如下代碼連接ftp服務器
constants cons_key type i value 26101957.
data:lv_pwd(64) type c,
lv_handle type i,
lv_length type i,
lv_pwdlen type i.
lv_pwd = is_ftpinfo-password.
lv_pwdlen = strlen( lv_pwd ).
*密碼加密
call function 'HTTP_SCRAMBLE'
exporting
source = lv_pwd
sourcelen = lv_pwdlen
key = cons_key
importing
destination = lv_pwd.
do 3 times." 連接三次,以爲一次可能會不成功
* 連接FTP服務器
call function 'FTP_CONNECT'
exporting
user = is_ftpinfo-username
password = lv_pwd "PASS WORD
host = is_ftpinfo-host
rfc_destination = 'SAPFTPA' "DEFAULT
importing
handle = ev_handle
exceptions
not_connected = 1
others = 2.
if sy-subrc = 0.
exit.
endif.
enddo.
rv_subrc = sy-subrc.