Chinaunix首页 | 论坛 | 博客
  • 博客访问: 684397
  • 博文数量: 194
  • 博客积分: 7067
  • 博客等级: 少将
  • 技术积分: 2008
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 14:48
个人简介

我很好

文章分类

全部博文(194)

文章存档

2019年(1)

2018年(1)

2017年(3)

2015年(2)

2012年(2)

2011年(1)

2010年(27)

2009年(15)

2008年(142)

分类: WINDOWS

2008-04-23 08:46:40

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 .
DATABEGIN OF blob OCCURS 0,
  line(100TYPE x,
  END OF blob.


PARAMETERS:
user(30TYPE c LOWER CASE DEFAULT 'test',
pwd(30TYPE c LOWER CASE DEFAULT 'test',
host(64TYPE c LOWER CASE DEFAULT '172.16.0.113',
filename(80TYPE c ,
name2(80TYPE 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.

  WRITEAT / '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.
  WRITEAT / '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) |
给主人留下些什么吧!~~