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

regaring file from FTP server to application server

Former Member
0 Likes
661

Hi frnds,

Below is my code where i am transferring Presentation server file to FTP server.

Now i want to transfer that file from FTP server to application server.

any help. below i am providing my code.

<code>

&----


*& Report demo

*&

&----


report z_demo_ftp.

  • Variables declaration

data : mi_handle type i,

pwd type char30,

slen type i,

key type i value 26101957,

it_file2 type filetable,

w_file2 like line of it_file2,

l_rc type i,

v_index type i,

v_file(30) type c,

v_path(100) type c,

v_path_tmp(100) type c.

*Internal table declaration

data: begin of mtab_data occurs 0,

line(132) type c,

end of mtab_data.

  • Selection scree parameters

parameters: p_file type string default 'C:\'.

  • Get the file path

at selection-screen on value-request for p_file.

data: p_file1 type string.

p_file1 = p_file.

call method cl_gui_frontend_services=>file_open_dialog

exporting

default_filename = p_file1

changing

file_table = it_file2

rc = l_rc

exceptions

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

else.

read table it_file2 into w_file2 index 1.

p_file = w_file2-filename.

clear w_file2.

refresh it_file2.

split p_file at '\' into table it_file2.

describe table it_file2 lines v_index.

read table it_file2 into w_file2 index v_index.

concatenate 'put' w_file2-filename into v_file separated by space.

delete it_file2 index v_index.

clear w_file2.

loop at it_file2 into w_file2.

if sy-tabix = 1.

v_path = w_file2-filename.

endif.

if sy-tabix ge 2.

concatenate v_path '\' w_file2 into v_path.

endif.

endloop.

concatenate 'lcd' v_path into v_path_tmp separated by space.

endif.

  • Start of selection

start-of-selection.

pwd = 'file456'.

slen = strlen( pwd ).

call function 'HTTP_SCRAMBLE'

exporting

source = pwd

sourcelen = slen

key = key

importing

destination = pwd.

  • Connect to FTP

call function 'FTP_CONNECT'

exporting

user = 'client'

password = pwd

host = 'saturn'

rfc_destination = 'SAPFTP'

importing

handle = mi_handle

exceptions

not_connected = 1

others = 2.

*

if sy-subrc = 0.

  • Excute FTP command

call function 'FTP_COMMAND'

exporting

handle = mi_handle

command = 'cd staff

tables

data = mtab_data

exceptions

tcpip_error = 1

command_error = 2

data_error = 3

others = 4.

  • Excute FTP command

call function 'FTP_COMMAND'

exporting

handle = mi_handle

command = v_path_tmp

tables

data = mtab_data

exceptions

tcpip_error = 1

command_error = 2

data_error = 3

others = 4.

  • Excute FTP command

call function 'FTP_COMMAND'

exporting

handle = mi_handle

command = v_file

tables

data = mtab_data

exceptions

tcpip_error = 1

command_error = 2

data_error = 3

others = 4.

*

if sy-subrc = 0.

loop at mtab_data.

write: / mtab_data.

endloop.

endif.

endif.

*FTP disconnect

call function 'FTP_DISCONNECT'

exporting

handle = mi_handle

exceptions

others = 1.call function 'FTP_DISCONNECT'

exporting

handle = mi_handle

exceptions

others = 1.

end-of-selection.

</code>

so what more code shuld i write.

regards,

kamal

Hi frnds,

Below is my code where i am transferring Presentation server file to FTP server.

Now i want to transfer that file from FTP server to application server.

any help. below i am providing my code.

<code>

&----


*& Report demo

*&

&----


report z_demo_ftp.

  • Variables declaration

data : mi_handle type i,

pwd type char30,

slen type i,

key type i value 26101957,

it_file2 type filetable,

w_file2 like line of it_file2,

l_rc type i,

v_index type i,

v_file(30) type c,

v_path(100) type c,

v_path_tmp(100) type c.

*Internal table declaration

data: begin of mtab_data occurs 0,

line(132) type c,

end of mtab_data.

  • Selection scree parameters

parameters: p_file type string default 'C:\'.

  • Get the file path

at selection-screen on value-request for p_file.

data: p_file1 type string.

p_file1 = p_file.

call method cl_gui_frontend_services=>file_open_dialog

exporting

default_filename = p_file1

changing

file_table = it_file2

rc = l_rc

exceptions

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

else.

read table it_file2 into w_file2 index 1.

p_file = w_file2-filename.

clear w_file2.

refresh it_file2.

split p_file at '\' into table it_file2.

describe table it_file2 lines v_index.

read table it_file2 into w_file2 index v_index.

concatenate 'put' w_file2-filename into v_file separated by space.

delete it_file2 index v_index.

clear w_file2.

loop at it_file2 into w_file2.

if sy-tabix = 1.

v_path = w_file2-filename.

endif.

if sy-tabix ge 2.

concatenate v_path '\' w_file2 into v_path.

endif.

endloop.

concatenate 'lcd' v_path into v_path_tmp separated by space.

endif.

  • Start of selection

start-of-selection.

pwd = 'file456'.

slen = strlen( pwd ).

call function 'HTTP_SCRAMBLE'

exporting

source = pwd

sourcelen = slen

key = key

importing

destination = pwd.

  • Connect to FTP

call function 'FTP_CONNECT'

exporting

user = 'client'

password = pwd

host = 'saturn'

rfc_destination = 'SAPFTP'

importing

handle = mi_handle

exceptions

not_connected = 1

others = 2.

*

if sy-subrc = 0.

  • Excute FTP command

call function 'FTP_COMMAND'

exporting

handle = mi_handle

command = 'cd staff

tables

data = mtab_data

exceptions

tcpip_error = 1

command_error = 2

data_error = 3

others = 4.

  • Excute FTP command

call function 'FTP_COMMAND'

exporting

handle = mi_handle

command = v_path_tmp

tables

data = mtab_data

exceptions

tcpip_error = 1

command_error = 2

data_error = 3

others = 4.

  • Excute FTP command

call function 'FTP_COMMAND'

exporting

handle = mi_handle

command = v_file

tables

data = mtab_data

exceptions

tcpip_error = 1

command_error = 2

data_error = 3

others = 4.

*

if sy-subrc = 0.

loop at mtab_data.

write: / mtab_data.

endloop.

endif.

endif.

*FTP disconnect

call function 'FTP_DISCONNECT'

exporting

handle = mi_handle

exceptions

others = 1.call function 'FTP_DISCONNECT'

exporting

handle = mi_handle

exceptions

others = 1.

end-of-selection.

</code>

so what more code shuld i write.

regards,

kamal

4 REPLIES 4
Read only

che_eky
Active Contributor
0 Likes
644

Your code is almost there just use the GET command instead of the PUT command.

Read only

Former Member
0 Likes
644

Hi Che Eky ,

Actually the above code is for putting the presentation server file to FTP Server.

But now i need to Put the same file present in the FTP server to Application server.

So any help or code which will be helpful.

regards,

kamal

Read only

Former Member
0 Likes
644

Any help frnds... plz help me...

regards,

kamal....

Read only

0 Likes
644

Any help frnds.

regards,

kamal.