由于R&D中心需要把图纸上传到FTP服务器上,所以做了一个FTP方式的上传本地文件到FTP服务器的程序,程序做完但是出现了一些问题,贴出来大家讨论,以便给予本人解决。现谢谢各位的参与和恢复。
问题:
1、上传的文件名称为英文或数字时没有问题,但是当文件名为中文时,传到服务器上的文件中文名称部分就全变为了#号。
例如:本地文件名为:FILE123.TXT 上传到服务器上文件名称还是为:FILE123.TXT
本地文件名为:文件123.TXT 上传到服务器上文件名称变成了:###123.TXT
在调试跟中时走道CALL FUNCTION 'FTP_R3_TO_SERVER' 时,name2在系统中还是中文显示,
函数完成,程序结束,文件传到服务器上,名称变为#号。
2、如果服务器上存放文件的路径有中文,上传出现错误。
例如:服务器路径
保存文件/
第一种 filename = '/SAVEFILE/FILE123.TXT'.
第二种 filename = '/保存文件/FILE123.TXT'.
CONCATENATE filename '' INTO name2.
这两种格式,第一种文件上传成功,第二种提示“FTP子命令:服务器报表错误”。
按照网上的提示把系统变量SAP_CODEPAGE 设置为 8400 等,都没有解决问题.
测试FTP 服务器为WIN2003 SERVER版,系统自带IIS设置.
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.
DATA: result TYPE TABLE OF text WITH HEADER LINE.
DATA:filename1 TYPE string,
path TYPE string,
fullpath TYPE string.
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.128',
filename(80) TYPE c DEFAULT 'test.xls',
name2(80) TYPE c DEFAULT 'test.xls',
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 SCREEN 100.
*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.
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 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
*----------------------------------------------------------------------*
* MODULE user_command_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'EXIT'.
CALL FUNCTION 'GUI_FILE_LOAD_DIALOG'
EXPORTING
window_title = 'DWG引入'
default_extension = 'DWG'
* DEFAULT_FILE_NAME = 'DWG'
* WITH_ENCODING =
* FILE_FILTER =
initial_directory = 'C:\'
IMPORTING
filename = filename1
path = path
fullpath = fullpath
* USER_ACTION =
* FILE_ENCODING =
.
filename1 = fullpath.
ENDCASE.
CLEAR sy-ucomm.
ENDMODULE. " USER_COMMAND_0100 INP
阅读(4089) | 评论(2) | 转发(0) |