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: 

Transfer Internal table Data to differents Local System using FTP in BGrnd

Former Member
0 Kudos
302

Hi Experts. . .

I got a Requirement( I Searched alot in Forums but i couldnt get Exact to my requirement)

I need to transfer internal data to anothers Servers Local file in Back Ground. Below is the code i am using in Fore ground its working fine but in Back Ground its not working. Please help me.

CONSTANTS : c_dest TYPE rfcdes-rfcdest VALUE 'SAPFTP',
                        c_ftp(6) TYPE c VALUE 'FTPDIRECTORY'.

* if I use c_dest TYPE rfcdes-rfcdest VALUE 'SAPFTPA'.  Its not even connecting

SET EXTENDED CHECK OFF.
l_slen = STRLEN( p_pwd ).

CALL FUNCTION 'HTTP_SCRAMBLE'
  EXPORTING
    SOURCE      = p_pwd
    sourcelen   = l_slen
    key         = c_key
  IMPORTING
    destination = l_pwd.

CONDENSE: p_user, l_pwd.
CALL FUNCTION 'FTP_CONNECT'
  EXPORTING
    user                   =  p_user
    password               =  l_pwd
*        ACCOUNT                =
    host                   =   c_host
    rfc_destination        =   c_dest
*        GATEWAY_USER           =
*        GATEWAY_PASSWORD       =
*        GATEWAY_HOST           =
 IMPORTING
   handle                 = w_hdl
 EXCEPTIONS
   not_connected          = 1
   OTHERS                 = 2
          .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*       MESSAGE TEXT-E01 TYPE 'I'.
*       LEAVE LIST-PROCESSING.
ENDIF.


CLEAR wrk_file.
wrk_file = '\\Tfbpfileserver\tc\JDESAP_ADS\TEST\SAMADS_TEST.TXT'.
CALL FUNCTION 'FTP_R3_TO_CLIENT'
  EXPORTING
    fname                 = wrk_file
    rfc_destination       = c_dest
**   BLOB_LENGTH           =
    character_mode        = 'X'
 TABLES
*   BLOB                  =
    text                  = it_result
 EXCEPTIONS
   command_error         = 1
   data_error            = 2
   OTHERS                = 3
          .
IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

* To disconnect the FTP
CALL FUNCTION 'FTP_DISCONNECT'
  EXPORTING
    handle = w_hdl.

CALL FUNCTION 'RFC_CONNECTION_CLOSE'
  EXPORTING
    destination = c_dest
  EXCEPTIONS
    OTHERS      = 1.

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos
176

It is standard behavior, SAPFTP use SapGUI (start on front end workstation checked) where SAPFTPA (start on explicit host) don't, so use of the second one in background is mandatory.

Test SAPFTPA via SM59 ([Note 93042 - Problems with SAPFTP|https://service.sap.com/sap/support/notes/93042]) can help you) - if error arise, delete wrong RFC destination SAPFTPA and recreate it via report RSFTP005.

Regards,

Raymond

7 REPLIES 7

raymond_giuseppi
Active Contributor
0 Kudos
177

It is standard behavior, SAPFTP use SapGUI (start on front end workstation checked) where SAPFTPA (start on explicit host) don't, so use of the second one in background is mandatory.

Test SAPFTPA via SM59 ([Note 93042 - Problems with SAPFTP|https://service.sap.com/sap/support/notes/93042]) can help you) - if error arise, delete wrong RFC destination SAPFTPA and recreate it via report RSFTP005.

Regards,

Raymond

0 Kudos
176

Hi,

If i pass c_dest = "SAPFTPA'. and i have put that in Debugging then i am getting sy-subrc = 1. means its failing to connet but with SAPFTP its connecting. i looks the connection is ok. the problem is at FTP_R3_TO_CLIENT. Can you please analyse and help me sample code.

Regards,

0 Kudos
176

I'm used to call some FTP_COMMAND (get, put, delete, etc. with parameters) and not FTP_R3_TO_CLIENT, and don't have any problem with SAPFTPA.

Regards,

Raymond

0 Kudos
176

Hi,

Even FTP_CONNECT itself not working in Background I tried with both rfc_destination = 'SAPFTP' and rfc_destination = 'SAPFTPA'. Can u please tell me what could be the reason. But in fore ground rfc_destination = 'SAPFTP' is working . But 'SAPFTPA' is not working. Please guide me when your precious time allows.

CALL FUNCTION 'FTP_CONNECT'
  EXPORTING
    user                   =  p_user
    password               =  l_pwd
*        ACCOUNT                =
    host                   =   c_host
    rfc_destination        =   c_dest
*        GATEWAY_USER           =
*        GATEWAY_PASSWORD       =
*        GATEWAY_HOST           =
 IMPORTING
   handle                 = w_hdl
 EXCEPTIONS
   not_connected          = 1
   OTHERS                 = 2
          .
IF sy-subrc <> 0.
*  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*       MESSAGE TEXT-E01 TYPE 'I'.
*       LEAVE LIST-PROCESSING.
 WRITE 'Not Connected'.
ENDIF.

Regards,

Edited by: Thomas Zloch on Jan 24, 2012 - urgency normalized by moderator

0 Kudos
176

Destination SAPFTP should only work online, as it uses SAP Gui (presentation server , SAPFTPA should work in both case as it uses the application server. Did you destroy and recreate SAPFTPA as explained before ?

Regards,

Raymond

0 Kudos
176

Hi,

the FTP_CONNECT is working fine but now i am getting command_error when i execute it in background. can u please tell me what could be the issue. iam usig c_dest = 'SAPFTPA'. or can you please help me with sample links

CLEAR wrk_file.

wrk_file = '
Tfbpfileserver\tc\JDESAP_ADS\TEST\SAMADS_TEST.TXT'.

CALL FUNCTION 'FTP_R3_TO_CLIENT'

EXPORTING

fname = wrk_file

rfc_destination = c_dest

    • BLOB_LENGTH =

character_mode = 'X'

TABLES

  • BLOB =

text = it_result

EXCEPTIONS

command_error = 1

data_error = 2

OTHERS = 3

.

IF sy-subrc 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Regards,

Neetha

former_member214857
Contributor
0 Kudos
176

Hi

Actually functions like FTP_CONNECT or FTP_R3_TO_CLIENT are released internally. So what you can do is,

1. Create your own functions to perform FTP process, can be a copy of standard functions

2. Adjust the code as your needs and save data in target location usign RFC communication

Best regards