Application Development and Automation 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: 
Read only

Problem in FTP

Former Member
0 Likes
659

Hi experts,

i am getting error at FTP_SERVER_TO_R3 FM .

it is giving sy-subrc = 2 (command error)

please suggest me what could be wrong in this.

REPORT ZGTSI_FTP2R3.

DATA: BEGIN OF t_data OCCURS 0,

line(132) TYPE c,

END OF t_data,

v_string(25) TYPE c.

DATA: gv_string(255) TYPE c,

gv_length TYPE i,

gv_fname1(255) TYPE c,

gv_fname2(255) TYPE c.

TYPES: BEGIN OF ty_text,

line(255) TYPE c,

END OF ty_text.

TYPES: BEGIN OF ty_blob,

line(255) TYPE x,

END OF ty_blob.

DATA: t_blob TYPE TABLE OF ty_blob ,

x_blob TYPE ty_blob.

DATA: t_text TYPE TABLE OF ty_text ,

x_text TYPE ty_text.

DATA: gv_password(40) TYPE c,

gv_password1 type string,

gv_fnam_appln(255) TYPE c,

gv_key TYPE i VALUE 26101957,

gv_pwd_len TYPE i,

gv_handle TYPE i.

START-OF-SELECTION.

*-- Your SAP-UNIX FTP password (case sensitive)

gv_password = XXXX.

gv_password1 = gv_password.

  • DESCRIBE FIELD gv_password LENGTH gv_pwd_len in byte mode.

gv_pwd_len = strlen( gv_password1 ).

**-- FTP_CONNECT requires an encrypted password to work

  • CALL 'AB_RFC_X_SCRAMBLE_STRING'

  • ID 'SOURCE' FIELD gv_password ID 'KEY' FIELD gv_key

  • ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD gv_password

  • ID 'DSTLEN' FIELD gv_pwd_len.

CALL FUNCTION 'HTTP_SCRAMBLE'

EXPORTING

SOURCE = gv_password

SOURCELEN = gv_pwd_len

KEY = gv_key

IMPORTING

DESTINATION = gv_password

.

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

*-- Your SAP-UNIX FTP user name (case sensitive)

user = XXXX

password = gv_password

*-- Your SAP-UNIX server host name (case sensitive)

host = XXXX

rfc_destination = 'SAPFTP'

IMPORTING

handle = gv_handle

EXCEPTIONS

not_connected = 1

OTHERS = 2.

if sy-subrc = 0.

CLEAR: gv_fname1,gv_fnam_appln.

CONCATENATE 'mkdenialsepextended_delta' sy-datum '.xml' INTO gv_fname1.

CONDENSE gv_fname1.

CONCATENATE '/usr/sap/tmp/' 'mkd1.txt'

INTO gv_fnam_appln.

PERFORM ftp_server_r3 USING gv_fname1 gv_fnam_appln.

CLEAR: gv_fname1,gv_fnam_appln.

CONCATENATE 'mkdenialSAPGL_delta' sy-datum '.xml' INTO gv_fname1.

CONDENSE gv_fname1.

CONCATENATE '/usr/sap/tmp/' 'mkd1.xml'

INTO gv_fnam_appln.

PERFORM ftp_server_r3 USING gv_fname1 gv_fnam_appln.

else.

write:/ 'FTP not connected'.

endif.

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = gv_handle

EXCEPTIONS

OTHERS = 1.

&----


*& Form ftp_server_r3

&----


  • text

----


  • -->P_GV_FNAME1 text

  • -->P_GV_FNAM_APPLN text

----


FORM ftp_server_r3 USING p_gv_fname1

p_gv_fnam_appln.

DATA: lv_cmd(255) TYPE c .

CALL FUNCTION 'FTP_SERVER_TO_R3'

EXPORTING

handle = gv_handle

fname = p_gv_fname1

character_mode = 'X'

IMPORTING

blob_length = gv_length

TABLES

blob = t_blob

text = t_text

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

WRITE:/ 'file does not exist in FTP' , 50 p_gv_fname1.

ELSE.

OPEN DATASET p_gv_fnam_appln FOR OUTPUT IN TEXT MODE encoding UTF-8 .

IF sy-subrc = 0.

LOOP AT t_text INTO x_text.

TRANSFER x_text TO gv_fnam_appln.

ENDLOOP.

IF sy-subrc EQ 0.

CONCATENATE 'delete' p_gv_fname1 INTO lv_cmd SEPARATED BY space.

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = gv_handle

command = lv_cmd

TABLES

data = t_data

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

WRITE 😕 p_gv_fnam_appln, 'uploaded with contents'.

ELSE.

WRITE:'File could not be opened',60 p_gv_fnam_appln.

ENDIF.

CLOSE DATASET p_gv_fnam_appln.

ENDIF.

ENDIF.

CLEAR: p_gv_fname1,p_gv_fnam_appln,lv_cmd.

ENDFORM. " ftp_server_r3

Thanks and regards

s.janagar

5 REPLIES 5
Read only

Former Member
0 Likes
565

solved my myself

Read only

Former Member
0 Likes
565

I am want send xls file using FTP. can you send any code?

Is this default RFC connect 'SAPFTP' . do we need to create?

Read only

0 Likes
565

you want to send XLS file from your desktop or application server, if it is from your desktop then connection destination will be 'SAPFTP' from application server from SAPFTPA

cheers

s.janagar

Read only

0 Likes
565

I have create xls file from my program and then FTP that .

Do I need to create the RFC destination SAPFTPA .. or is it by default creted by SAP.

plz attach if any code exist?

Read only

0 Likes
565

please looki into this wiki

https://wiki.sdn.sap.com/wiki/display/Snippets/ABAP%20solution%20to%20implement%20FTP%20transactions

and one more thing

please google this content for SAPFTPUnix

you will get lot of idea

and try checking in SM59 is this connection exits are not

if not you need to get it created by basis people

main things required are

IP address of the host which u like to connect

user id

pwd

if these three things are there you may able to solve your issue

cheers

s.janagar