Skip to Content

Command Error from FTP_R3_TO_SERVER

Hi Experts,

I am facing one issue of Read & Write the csv file from FTP Server.

If i try to Write the csv file from SAP to FTP server, File name is creating with given name and given extension but When i open this file value is are not getting stored.

and Also FM FTP_R3_TO_SERVER giving Command error.

Kindly anyone help me out to resolve the issue.

Below my code.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME TITLE text-001.
PARAMETERS:
pa_user TYPE c LENGTH 30 LOWER CASE OBLIGATORY,"FTP Server User
pa_pswrd TYPE c LENGTH 30 LOWER CASE OBLIGATORY ,"FTP Server User's Password
pa_host TYPE c LENGTH 64 LOWER CASE OBLIGATORY,"IP Address of the FTP Server
pa_rfcds LIKE rfcdes-rfcdest OBLIGATORY DEFAULT 'SAPFTP'. "RFC Destination,SAPFTP for Frontend communications(Local Connections) .
SELECTION-SCREEN: END OF BLOCK a.

DATA:
mi_key TYPE i VALUE 26101957,"Hardcoded Handler Key,This is always '26101957'
mi_pwd_len TYPE i ,"For finding the length of the Password,This is used when scrambling the password
mi_handle TYPE i."Handle for Pointing to an already connected FTP connection,used for subsequent actions on the connected FTP session

DATA:
it_sflight TYPE STANDARD TABLE OF crmd_orderadm_h,"Final Internal table to be uploaded as a Text file on an FTP Server
wa_sflight LIKE LINE OF it_sflight.

Data : begin of it_final occurs 0 ,
str(125) ,
end of it_final,
wa_final like line of it_final.

"FTP Communication Data Objects - [END]

SET EXTENDED CHECK OFF.
mi_pwd_len = STRLEN( pa_pswrd ).

CALL FUNCTION 'HTTP_SCRAMBLE'"For Encrypting the Password
EXPORTING
SOURCE = pa_pswrd
sourcelen = mi_pwd_len
key = mi_key
IMPORTING
destination = pa_pswrd.

CALL FUNCTION 'FTP_CONNECT'"For connecting to the FTP Server's user directory
EXPORTING
user = pa_user
password = pa_pswrd
host = pa_host
rfc_destination = pa_rfcds "Using the Background SAP FTP Library as part of the SAP backend System
IMPORTING
handle = mi_handle
EXCEPTIONS
not_connected = 1
OTHERS = 2.

IF sy-subrc = 0."When FTP connection established Successfully

SELECT * from crmd_orderadm_h
INTO TABLE it_sflight UP TO 10 ROWS.
*
* APPEND wa_sflight to it_sflight.
*
* "Final Internal table with a String
* concatenate wa_sflight-carrid wa_sflight-connid wa_sflight-fldate wa_sflight-planetype "wa_sflight-seatsmax wa_sflight-seatsocc
* into wa_final-str SEPARATED BY ' '.
* APPEND wa_final to it_final.

* ENDSELECT.

LOOP AT it_sflight INTO wa_sflight.
CONCATENATE wa_sflight-object_id wa_sflight-process_type INTO wa_final SEPARATED BY ','.
APPEND wa_final to it_final.
ENDLOOP.


DATA : path(58) ."Path that points to the FTP User's Home Directory
DATA:extension(4).
extension = '.CSV' .

CONCATENATE '/exportcsv' sy-datum sy-uzeit extension INTO path .

CALL FUNCTION 'FTP_R3_TO_SERVER'"For Creating a file from SAP R3 to FTP Server
EXPORTING
handle = mi_handle
fname = path
character_mode = 'X'
TABLES
text = it_final"Final Internal table to be written to the text file in the FTP Server's Directory
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
*** Here getting ,sy-subrc = 2 ***************


ELSE."When FTP connection Fails
WRITE: / 'Error in FTP Command'.
ENDIF.

CALL FUNCTION 'FTP_DISCONNECT'"For Disconnecting the connected FTP Session
EXPORTING
handle = mi_handle
EXCEPTIONS
OTHERS = 1.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Jun 29, 2016 at 04:19 AM

    Finally solved the issue.

    After connecting FTP server, I set passive mode on.

    CALL FUNCTION 'FTP_COMMAND'
    EXPORTING
    handle = mi_handle
    command = 'set passive on'
    TABLES
    data = result
    EXCEPTIONS
    command_error = 1
    tcpip_error = 2.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 15, 2016 at 08:48 AM

    Could you first do the basic verifications as explained in note 93042 - Problems with SAPFTP -> https://service.sap.com/sap/support/notes/93042

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 15, 2016 at 04:28 AM

    Hi,

    Anyone help me out.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.