
Sunday, November 20, 2011
at
11:08 PM
|
0
comments
Here is an example of how to FTP a file from the Application server to a remote server using standard SAP functions.
REPORT YSANTO_12 .
data: begin of gi_data occurs 0,
      line(132) type c,
  end of gi_data.
data: lv_password(20) type c,
  lv_key type i value 26101957,
  lv_pwd_len type I,
  lv_handle type I.
START-OF-SELECTION.
lv_password = 'password'.
describe field lv_password length lv_pwd_len in character mode.
call 'AB_RFC_X_SCRAMBLE_STRING'
    id 'SOURCE' field lv_password id 'KEY' field lv_key
    id 'SCR' field 'X' id 'DESTINATION' field lv_password
    id 'DSTLEN' field lv_pwd_len.
call function 'FTP_CONNECT'
  exporting
  user = 'userid'
  password = lv_password
  host = 'host'
  rfc_destination = 'SAPFTP'
  importing
  handle = lv_handle
  exceptions
  not_connected = 1
  others = 2.
check sy-subrc = 0.
call function 'FTP_COMMAND'
  exporting
  handle = lv_handle
  command = 'dir' " for get file -> exe commnad 'asci'
  tables " then exe command 'get sourcefile targetfile'.
  data = gi_data
  exceptions
  tcpip_error = 1
  command_error = 2
  data_error = 3
  others = 4.
call function 'FTP_DISCONNECT'
  exporting
  handle = lv_handle
  exceptions
  others = 1.
REPORT YSANTO_12 .
data: begin of gi_data occurs 0,
      line(132) type c,
  end of gi_data.
data: lv_password(20) type c,
  lv_key type i value 26101957,
  lv_pwd_len type I,
  lv_handle type I.
START-OF-SELECTION.
lv_password = 'password'.
describe field lv_password length lv_pwd_len in character mode.
call 'AB_RFC_X_SCRAMBLE_STRING'
    id 'SOURCE' field lv_password id 'KEY' field lv_key
    id 'SCR' field 'X' id 'DESTINATION' field lv_password
    id 'DSTLEN' field lv_pwd_len.
call function 'FTP_CONNECT'
  exporting
  user = 'userid'
  password = lv_password
  host = 'host'
  rfc_destination = 'SAPFTP'
  importing
  handle = lv_handle
  exceptions
  not_connected = 1
  others = 2.
check sy-subrc = 0.
call function 'FTP_COMMAND'
  exporting
  handle = lv_handle
  command = 'dir' " for get file -> exe commnad 'asci'
  tables " then exe command 'get sourcefile targetfile'.
  data = gi_data
  exceptions
  tcpip_error = 1
  command_error = 2
  data_error = 3
  others = 4.
call function 'FTP_DISCONNECT'
  exporting
  handle = lv_handle
  exceptions
  others = 1.
Posted by
Shanto
Labels:
ABAP,
ABAP Function