REPORT z7258_local2ftp .
DATA: hdl TYPE i,
key TYPE i VALUE 26101957,
dstlen TYPE i,
blob_length TYPE i.
DATA filepath TYPE string .
DATA: BEGIN OF blob OCCURS 0,
line(100) TYPE x,
END OF blob.
PARAMETERS: user(64) TYPE c ,
pwd(64) TYPE c ,
host(64) TYPE c ,
filename(80) TYPE c ,
name2(80) TYPE c,
dest LIKE rfcdes-rfcdest DEFAULT 'SAPFTP'.
PARAMETERS: p_file LIKE rlgrap-filename
DEFAULT 'c:\test.xls'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_p_file USING p_file text-006.
START-OF-SELECTION.
CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD pwd ID 'KEY' FIELD key
ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD pwd
ID 'DSTLEN' FIELD dstlen.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = user
password = pwd
host = host
rfc_destination = dest
IMPORTING
handle = hdl.
*CALL FUNCTION 'FTP_SERVER_TO_R3'
* EXPORTING HANDLE = HDL FNAME = FILENAME
* IMPORTING BLOB_LENGTH = BLOB_LENGTH
* TABLES BLOB = BLOB.
filepath = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filepath
filetype = 'BIN'
IMPORTING
filelength = blob_length
TABLES
data_tab = blob.
CALL FUNCTION 'CH_SPLIT_FILENAME'
EXPORTING
complete_filename = filepath
IMPORTING
name_with_ext = name2.
WRITE: AT / 'Get ',p_file,' Length: ',blob_length.
* CONCATENATE filename '' INTO name2.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = hdl
fname = name2
blob_length = blob_length
TABLES
blob = blob.
* CALL FUNCTION 'FTP_COMMAND'
* EXPORTING
* handle = hdl
* command = 'PUT'
* IMPORTING
* filesize = blob_length
* TABLES
* data = blob.
WRITE: AT / 'Put ',name2.
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = hdl.
*&---------------------------------------------------------------------*
*& Form get_p_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_FILE text
* -->P_TEXT_006 text
*----------------------------------------------------------------------*
FORM get_p_file USING l_filename
l_text.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = space
def_path = l_filename
mask = ',*.xls ,*.xls.'
mode = 'O'
title = l_text
IMPORTING
filename = l_filename
EXCEPTIONS
inv_winsys = 04
no_batch = 08
selection_cancel = 12
selection_error = 16.
ENDFORM. " get_p_file
*Text elements
*----------------------------------------------------------
* 006 请输入文件名
这段程序测试过,出现用户没有权利访问服务器的错误 做了如下修改,
连接信息由大写调整为小写,增加了密码转换
*&-------------------------------------------------------*
*& Report ZTEST_NYJ
*&
*&------------------------------------------*
*&
*&
*&--------------------------*
REPORT ztest_nyj MESSAGE-ID zmc01 NO STANDARD PAGE HEADING LINE-SIZE 500.
DATA: hdl TYPE i,
key TYPE i VALUE 26101957,
dstlen TYPE i,
slen TYPE i,
blob_length TYPE i.
DATA filepath TYPE string .
DATA: BEGIN OF blob OCCURS 0,
line(100) TYPE x,
END OF blob.
PARAMETERS:
user(30) TYPE c LOWER CASE DEFAULT 'test',
pwd(30) TYPE c LOWER CASE DEFAULT 'test',
host(64) TYPE c LOWER CASE DEFAULT '172.16.0.113',
filename(80) TYPE c ,
name2(80) TYPE c,
dest LIKE rfcdes-rfcdest DEFAULT 'SAPFTP'.
PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'c:\test.xls'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_p_file USING p_file text-006.
START-OF-SELECTION.
*END-OF-SELECTION .
CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD pwd
ID 'KEY' FIELD key
ID 'SCR' FIELD 'X'
ID 'DESTINATION' FIELD pwd
ID 'DSTLEN' FIELD dstlen.
slen = STRLEN( pwd ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = pwd
sourcelen = slen
key = key
IMPORTING
destination = pwd.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = user
password = pwd
host = host
rfc_destination = dest
IMPORTING
handle = hdl.
*CALL FUNCTION 'FTP_SERVER_TO_R3'
* EXPORTING HANDLE = HDL FNAME = FILENAME
* IMPORTING BLOB_LENGTH = BLOB_LENGTH
* TABLES BLOB = BLOB.
filepath = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filepath
filetype = 'BIN'
IMPORTING
filelength = blob_length
TABLES
data_tab = blob.
write ''.
CALL FUNCTION 'CH_SPLIT_FILENAME'
EXPORTING
complete_filename = filepath
IMPORTING
name_with_ext = name2.
WRITE: AT / 'Get ',p_file,' Length: ',blob_length.
CONCATENATE filename '' INTO name2.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = hdl
fname = name2
blob_length = blob_length
TABLES
blob = blob.
* CALL FUNCTION 'FTP_COMMAND'
* EXPORTING
* handle = hdl
* command = 'PUT'
* IMPORTING
* filesize = blob_length
* TABLES
* data = blob.
WRITE: AT / 'Put ',name2.
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = hdl.
*&--------------------------------------------*
*& Form get_p_file*&---------------------------------*
* text*---------------------------------*
* -->P_P_FILE text
* -->P_TEXT_006 text
*-------------------------------------*
FORM get_p_file USING l_filename l_text.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = space
def_path = l_filename
mask = ',*.dwg ,*.dwg.'
mode = 'O'
title = l_text
IMPORTING
filename = l_filename
EXCEPTIONS
inv_winsys = 04
no_batch = 08
selection_cancel = 12
selection_error = 16.
ENDFORM. " get_p_file*Text elements
*----------------------------------------------------------* 006 请输入文件名
阅读(1235) | 评论(0) | 转发(0) |