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

FTP between two different servers

Former Member
0 Likes
396

Hi all,

I have two different servers viz, my Application Server and a Non-SAP server on which i have a file.

I receive a File on this Non-SAP server every hour.

I want to transfer this File From the Non-SAP server to my Application Server, so that i can use the File for further processing.

Any inputs on how do i map both the servers. I have connection with both the servers on my PC.

Thanks in advance.

Regards

Neo.

1 REPLY 1
Read only

rajeshkumar_kaveti
Participant
0 Likes
357

Hi,

Check the following code. It should help u.

DATA l_handle_src TYPE i.

DATA l_handle_dst TYPE i.

DATA s_pswd(64) TYPE c VALUE 'traning'.

DATA d_pswd(64) TYPE c VALUE 'hponly'.

DATA l_key TYPE i VALUE 26101957.

DATA l_dstlen TYPE i.

DATA l_command(60) TYPE c.

describe field s_pswd length l_dstlen in character mode.

  • Source FTP

*----


  • This system function will Encrypt the password

CALL 'AB_RFC_X_SCRAMBLE_STRING'

ID 'SOURCE' FIELD s_pswd ID 'KEY' FIELD l_key

ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD s_pswd

ID 'DSTLEN' FIELD l_dstlen.

  • This Function Module returns a handle, which is the pointer to the

  • instance of FTP

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

user = 'traning'

password = s_pswd

host = '172.16.0.122'

rfc_destination = 'SAPFTPA'

IMPORTING

handle = l_handle_src

EXCEPTIONS

not_connected = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

describe field d_pswd length l_dstlen in character mode.

  • Destination FTP

*----


CALL 'AB_RFC_X_SCRAMBLE_STRING'

ID 'SOURCE' FIELD d_pswd ID 'KEY' FIELD l_key

ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD d_pswd

ID 'DSTLEN' FIELD l_dstlen.

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

user = 'root'

password = d_pswd

host = '172.10.0.13'

rfc_destination = 'SAPFTPA'

IMPORTING

handle = l_handle_dst

EXCEPTIONS

not_connected = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

  • Set the Source And Destination File Names

*----


DATA: l_source_file LIKE rlgrap-filename

VALUE '/FLS_TEXT/',

l_dest_file(256) TYPE c

VALUE '/tmp/'.

DATA: BEGIN OF response OCCURS 0,

line(80) TYPE c,

END OF response.

CONCATENATE l_source_file filename '.txt' INTO l_source_file.

CONCATENATE l_dest_file 'FLS_DATA' '.txt' INTO l_dest_file.

*Copy the File from the Source Machine to the Application Server

*----


CALL FUNCTION 'FTP_COPY'

EXPORTING

handle_source = l_handle_src

handle_destination = l_handle_dst

file_source = l_source_file

file_destination = l_dest_file

TABLES

data = response

EXCEPTIONS

command_error = 1.

IF sy-subrc <> 0.

LOOP AT response.

ENDLOOP.

ELSE.

ENDIF.

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = l_handle_src.

CALL FUNCTION 'FTP_DISCONNECT'

EXPORTING

handle = l_handle_dst.

Regards,

Rajesh