CONSTANTS: cns_host TYPE c LENGTH 13 VALUE '172.168.1.250'.
CONSTANTS: cns_usr TYPE c LENGTH 7 VALUE 'username'.
CONSTANTS: cns_pwd TYPE c LENGTH 9 VALUE 'password'.
CONSTANTS: cns_key TYPE i VALUE 26101957."密钥
CONSTANTS: cns_rfcdest LIKE rfcdes-rfcdest VALUE 'SAPFTPA'.

DATA:lv_pwd(40),
       lv_len       TYPE i,
       ls_ftpserver TYPE sapftp_servers,
       lv_handle    TYPE i,
       lv_file(20),
       lo_csv       TYPE REF TO cl_rsda_csv_converter.
  DATA: BEGIN OF ls_line,
          line(2000),
        END OF ls_line,
        lt_line LIKE TABLE OF ls_line.

lv_len = strlen( cns_pwd ).
  CALL FUNCTION 'HTTP_SCRAMBLE'
    EXPORTING
      source      = cns_pwd
      sourcelen   = lv_len
      key         = cns_key
    IMPORTING
      destination = lv_pwd. "加密密码

  CLEAR ls_ftpserver.
  SELECT SINGLE * FROM sapftp_servers INTO ls_ftpserver
    WHERE ftp_server_name = cns_host AND ftp_server_port = 21.
  IF sy-subrc <> 0.
    ls_ftpserver-ftp_server_name = cns_host.
    ls_ftpserver-ftp_server_port = 21.
    ls_ftpserver-description = 'XXXFTP'.
    INSERT INTO sapftp_servers VALUES ls_ftpserver .
    COMMIT WORK AND WAIT.
  ENDIF.
  DO 3 TIMES.
    CALL FUNCTION 'FTP_CONNECT'
      EXPORTING
        user            = cns_usr
        password        = lv_pwd
*       ACCOUNT         =
        host            = cns_host
        rfc_destination = cns_rfcdest
*       GATEWAY_USER    =
*       GATEWAY_PASSWORD       =
*       GATEWAY_HOST    =
      IMPORTING
        handle          = lv_handle
      EXCEPTIONS
        not_connected   = 1
        OTHERS          = 2.
    IF sy-subrc = 0.
      EXIT.
    ENDIF.
  ENDDO.
lv_file = '......'.
CALL FUNCTION 'FTP_SERVER_TO_R3'
    EXPORTING
      handle         = lv_handle
      fname          = lv_file
      character_mode = 'X'
* IMPORTING
*     BLOB_LENGTH    =
    TABLES
*     BLOB           =
      text           = lt_line
    EXCEPTIONS
      tcpip_error    = 1
      command_error  = 2
      data_error     = 3
      OTHERS         = 4.
LOOP AT lt_line INTO ls_line.
ENDLOOP.

 

posted on 2018-05-31 13:09  小伙儿  阅读(878)  评论(0编辑  收藏  举报