Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Using FTPS in ABAP without SAP PI

mrio_espinheira
Participant
0 Kudos

Hello,

I have a requirement to create a file in an external server using FTPS and ABAP but we don't use SAP PI. My question is simple, is it possible?

If it's possible, do the following FM work?

call function 'HTTP_SCRAMBLE'
  exporting
    source      = lv_pwd
    sourcelen   = lv_pwd_len
    key         = lv_key
  importing
    destination = lv_pwd.


call function 'FTP_CONNECT'
  exporting
    user            = lv_user
    password        = lv_pwd
    host            = lv_host
    rfc_destination = lv_rfc_dest
  importing
    handle          = lv_handle
  exceptions
    not_connected   = 1
    others          = 2.
if sy-subrc ne 0.
  message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  exit.
endif.


call function 'FTP_R3_TO_SERVER'
  exporting
    handle         = lv_handle
    fname          = lv_filename
    character_mode = 'X'
  tables
    text           = lt_text
  exceptions
    tcpip_error    = 1
    command_error  = 2
    data_error     = 3
    others         = 4.
if sy-subrc ne 0.
  message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  exit.
endif.


call function 'FTP_DISCONNECT'
  exporting
    handle = lv_handle.

Regards,

Mário Espinheira

1 ACCEPTED SOLUTION

mrio_espinheira
Participant
0 Kudos

Hello,

The FM mentioned before didn't work for our specific requisit. We used a SM69 system command to execute a AS400 script that creates the FTP session (with the FTPS server installed in the application server) and executes the FTP commands stored in a DDIC table.

Hope this helps anyone with the same requirement.

Regards!

9 REPLIES 9

Former Member
0 Kudos

Never heard of FTPS, but if you mean SFTP....I did essentially what you're doing and it worked for me. GOOGLE SFTP and FTP commands...

I wrote a generic transfer FM to handle either direction; you can figure out what was in the include forms, I think:

before FM call:

data: lv_len      type i,
        lv_key      type i value 26101957,
        lv_password type tvarv_val.

  lv_len = strlen( lv_pass ).

  call function 'HTTP_SCRAMBLE'
    exporting
      source      = lv_pass
      sourcelen   = lv_len
      key         = lv_key
    importing
      destination = lv_password.

  if lv_password is not initial.
    update zcltt_edi_vars
      set low = lv_password
          sign = 'I'
          opti = 'EQ'
          high = space
    where name eq 'FTP_PASSWORD'
      and type eq 'P'
      and numb eq 1.
  endif.
  commit work.

FM IMPORT parameters:

XFER_FORMAT TYPE CHAR1 'A'

FTP_DIRECTION TYPE CHAR1 'I'

FTP_HOST TYPE C

FTP_USER TYPE C

FTP_PASSWORD TYPE C

RFC_DESTINATION TYPE RFCDEST

FTP_LOCAL_PATH TYPE LOCALFILE

FTP_FILE_NAME TYPE LOCALFILE

DELETE_AFTER_FTP TYPE BOOLEAN 'X'

* Developers Note:  Basis colleagues create a default folder on the
* FTP host. We cannot move out of that path, so there is no parameter
* for the remote system folder.
*
  data: lv_return    type sysubrc,
        lv_direction type char1,
        lv_transfer  type char1,
        lv_multiple  type boolean,
        lv_host       type char64.

  return_code = 0.
  lv_host = ftp_host. "specified by basis

  case ftp_direction.
    when gc_i or gc_o. "In or out
      lv_direction = ftp_direction.
    when others.
      raise invalid_ftp_direction.
  endcase.

  if xfer_format eq gc_a.
    lv_transfer = gc_a. "ASCII
  else.
    lv_transfer = gc_b. "BINARY
  endif.

  if ftp_file_name is initial.
    lv_multiple = abap_true.
  endif.

  perform ftp_open using ftp_user
                         ftp_password
                         lv_host
                         rfc_destination
                changing gv_handle
                         lv_return.
  if lv_return is not initial.
    raise unable_to_connect.
  endif.

  perform ftp_transfer_type using lv_transfer
                         changing lv_return.
  if lv_return is not initial.
    raise unable_to_set_transfer_type.
  endif.

  perform change_directory using ftp_local_path
                        changing lv_return.
  if lv_return is not initial.
    raise unable_to_change_folder.
  endif.

* handle transfer if file_name is populated;  after this point,
* the program should be allowed to continue through close...
  if lv_multiple eq abap_false.
    perform ftp_file_single using lv_direction
                                  ftp_file_name
                         changing lv_return.
    if lv_return is not initial.
      return_code = 4.
    endif.

    if delete_after_ftp eq abap_true and lv_return is initial.
      perform delete_file_single using lv_direction
                                       ftp_local_path
                                       ftp_file_name
                              changing lv_return.
      if lv_return is not initial.
        return_code = 6.
      endif.
    endif. "delete input is ON
  endif.   "Single file indicated

* handle transfers if file_name is not populated
  if lv_multiple eq abap_true.

    perform ftp_all_files using lv_direction
                       changing lv_return.
    if lv_return is not initial.
      return_code = 8.
    endif.

    if delete_after_ftp eq abap_true and lv_return is initial.
      perform delete_all_files using lv_direction
                                     ftp_local_path
                            changing lv_return.
      if lv_return is not initial.
        return_code = 12.
      endif.
    endif.    "Delete Input is ON

  endif.      "Multiple files indicated


  perform ftp_close using rfc_destination
                 changing lv_return.
  if lv_return is not initial.
    raise unable_to_close.
  endif.

  if return_code ne 0.
    raise ftp_errors_occurred.
  endif.

endfunction.

Edited by: BreakPoint on Feb 17, 2011 4:13 PM

mrio_espinheira
Participant
0 Kudos

Hello,

The FM mentioned before didn't work for our specific requisit. We used a SM69 system command to execute a AS400 script that creates the FTP session (with the FTPS server installed in the application server) and executes the FTP commands stored in a DDIC table.

Hope this helps anyone with the same requirement.

Regards!

0 Kudos

Hello Mário & Dave,

I have a similar requirement. I need to send a file using SFTP and we do not have a SAP XI system. Is it possible to send file only using ABAP. Can you please share some documents which will help me in achieving the requirement.

Thanks in advance.

Have a nice day.

Regards,

Venkat Varadan

Former Member
0 Kudos

Hi ,

For SFTP you can call Custom FM and inside use floowing command with FM parameters as filename and return table for any error while connection open . For filename pass SFTP script alogn wiht File complete path , user id , pws and all those parameters you have set in your shell script .This should work .

CALL FUNCTION 'RFC_REMOTE_PIPE' DESTINATION 'SERVER_EXEC'

EXPORTING

COMMAND = I_FILENAME

READ = 'X'

TABLES

PIPEDATA = TABL

EXCEPTIONS

OTHERS = 1.

Former Member
0 Kudos

Hola Mario,

Tengo el mismo problema que tu a la hora de acceder desde ABAP a un directorio de un servidor FTPs.

¿Al final conseguiste encontrar la solución?

Por mas que busco, no encuentre ningún ejemplo que pueda ayudarme....

Un cordial saludo

0 Kudos

Hello,

I didn't use the FM in question. As I replied on Apr 14, what worked for me was:

The FM mentioned before didn't work for our specific requisit. We used a SM69 system command to execute a AS400 script that creates the FTP session (with the FTPS server installed in the application server) and executes the FTP commands stored in a DDIC table.

Best regards,

Mário Espinheira

0 Kudos

ok understood, I could try to use a similar script that yours, but in unix.

Just one more thing: Would you have information on configuring FTPs in SAP (without PI)?   I do not know where to start 😞

Thanks for your answer Mario, best regards

0 Kudos

Hello,

Unfortunately since we resolved our problem with the AS/400 script I didn't pursue trying to get FTPs working on R/3 anymore, sorry.

Best of luck,

Mário Espinheira

0 Kudos

Ok Mario, thanks anyway.

Kind regards