SFTP Dosya Yükleme / Upload

SXPG_COMMAND_EXECUTE fonksiyonunun kullanımı



FUNCTION zzz_file_send_to_sftp.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_FNAME) TYPE  CHAR255 OPTIONAL
*"     VALUE(I_COMMAND_FILE) TYPE  XFELD OPTIONAL
*"  EXPORTING
*"     VALUE(ES_RETURN) TYPE  BAPIRET2
*"----------------------------------------------------------------------

  
DATA :  ls_additional_parameters  TYPE  sxpgcolist-parameters,
          lv_status  
TYPE  extcmdexex-status,
          lv_exitcode  
TYPE  extcmdexex-exitcode,
          lt_exec_protocol  
TYPE TABLE OF btcxpm WITH HEADER LINE,
          lv_commandname  
TYPE  sxpgcolist-name,
          lv_seperator 
TYPE c,
          lv_tmp_fullname
(512TYPE c,

          ls_password(40TYPE c,
          ls_username
(40TYPE c,
          ls_host
(40TYPE c,
          lv_connection_string
(255TYPE c,
          lv_fname_new
(255TYPE c,
          ls_ftps_folder
(255TYPE c.

  lv_commandname 
`ZSFLIST`."SM69 daki harici komut
  ls_host        
`secureftp.tumsoft.com`.
  ls_username    
`SFTPUSERNAME`.
  ls_password    
`SFTPPASSWORD`.

  
CLEAR lv_seperator.
  
FIND `/` IN i_fname.
  
IF sy-subrc EQ 0.
    lv_seperator 
`/`.
  
ELSE.
    lv_seperator 
``.
  
ENDIF.

  
CONCATENATE i_fname
              lv_seperator 
INTO lv_tmp_fullname.

  
PERFORM decode_password CHANGING ls_password.

  
"""connect ftps""
  
CONCATENATE `"open ftps://`
  ls_username 
`:` ls_password `@` ls_host
  
` -explicitssl"`
  
INTO lv_connection_string .

  
CONCATENATE lv_connection_string
  
`"cd` `/` `to_sf` `/` `"`
   
INTO ls_additional_parameters
   
SEPARATED BY space.

  
CONCATENATE lv_connection_string
  
`"put` lv_tmp_fullname `"`
  
`"exit"`
  
INTO ls_additional_parameters
  
SEPARATED BY space.


  
CALL FUNCTION `SXPG_COMMAND_EXECUTE`
    
EXPORTING
      commandname                   
lv_commandname
      additional_parameters         
ls_additional_parameters
    
IMPORTING
      status                        
lv_status
      exitcode                      
lv_exitcode
    
TABLES
      exec_protocol                 
lt_exec_protocol
    
EXCEPTIONS
      no_permission                 
1
      command_not_found             
2
      parameters_too_long           
3
      security_risk                 
4
      wrong_check_call_interface    
5
      program_start_error           
6
      program_termination_error     
7
      x_error                       
8
      parameter_expected            
9
      too_many_parameters           
10
      illegal_command               
11
      wrong_asynchronous_parameters 
12
      cant_enq_tbtco_entry          
13
      jobcount_generation_error     
14
      
OTHERS                        15.
  
IF sy-subrc <> OR lv_status EQ `E`.
    es_return
-type `E`.
    es_return
-id `ZTR_SF`.
    es_return
-number `001`.
    
EXIT.
  
ENDIF.


FORM 
decode_password  CHANGING p_password.

  
DATAencode  TYPE string,
        decode  
TYPE string .

  
DATAobj  TYPE REF TO cl_http_utility,
        cref 
TYPE REF TO if_http_utility.

  
CREATE OBJECT obj.

  cref 
obj.
  encode 
p_password.
  decode 
obj->if_http_utility~decode_base64encode ).
  p_password 
decode.

ENDFORM.                    " DECODE_PASSWORD