2006 Oct 13 9:18 AM
hi all,
i need to ftp internal table data to the specified destination.
the following info is provoded by the user.
<b>Server
Id/pwd
Directory</b>
i know using ftp_connect, i can connect by giving server and pwd.
but can any one tell me how to build the ftp_command now.
1)is cd /crs will be enough? or else i need the complete path where to store?
2)can i send the inetrna; table data or i need to create a file in the application server?
3) lastly can anybody explain me
call 'AB_RFC_X_SCRAMBLE_STRING'
id 'SOURCE' field dpwd id 'KEY' field key
id 'SCR' field 'X' id 'DESTINATION' field dpwd
id 'DSTLEN' field slen.
what is this and for what purpose it is used?
awaiting for the answers,
Thanks and regards
Hyma
2006 Oct 13 9:37 AM
Hi,
It is not wise to inlcude server with a userid/passwd in forums even if it's an internal machine.
Anyway, check /people/thomas.jung3/blog/2004/11/15/performing-ftp-commands-from-abap
on how to FTP from ABAP.
Eddy
PS.
Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
Spread the wor(l)d!
2006 Oct 13 9:43 AM
Hi Hyma,
The FM is for scrambling the password.
Look at the code below to have an idea how to do the ftp task.
Regards,
Raj
Find the RFC destination
IF sy-batch IS INITIAL.
l_rfc = 'SAPFTP'.
ELSE.
l_rfc = 'SAPFTPA'.
ENDIF.
Encrypt the password, Required for FTP connection
CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD v_ftppwd
ID 'KEY' FIELD l_key
ID 'SCR' FIELD 'X'
ID 'DESTINATION' FIELD v_ftppwd
ID 'DSTLEN' FIELD l_dstlen.
Open the FTP connection
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = v_ftpusr
password = v_ftppwd
host = v_ftpsrv
rfc_destination = l_rfc
IMPORTING
handle = v_hdl
EXCEPTIONS
not_connected = 01
OTHERS = 02.
IF sy-subrc NE 0.
MESSAGE e200(zhr) WITH 'Failed to open FTP connection!'(020).
ELSE.
FTP the file
PERFORM send_file.
Close the FTP connection
PERFORM close_ftp_connection.
ENDIF.
&----
*& Form send_file
&----
FTP the file
----
FORM send_file .
DATA: l_cmd(80) TYPE c,
l_fil(80) TYPE c,
l_loc TYPE i,
l_lng TYPE i.
DATA: BEGIN OF t_result OCCURS 0,
line(100) TYPE c,
END OF t_result.
Change remote directory
CLEAR l_cmd.
CONCATENATE 'cd' v_ftploc INTO l_cmd SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = v_hdl
command = l_cmd
TABLES
data = t_result
EXCEPTIONS
tcpip_error = 01
command_error = 02
data_error = 03
OTHERS = 04.
IF sy-subrc NE 0.
MESSAGE e200(zhr) WITH 'Unable to issue command:'(021) l_cmd.
ENDIF.
Find the local directory
l_loc = 1.
WHILE sy-subrc EQ 0.
SEARCH p_ofile FOR '/' STARTING AT l_loc.
IF sy-fdpos GT 0.
ADD sy-fdpos TO l_loc.
l_cmd = p_ofile(l_loc).
l_lng = 60 - l_loc.
l_fil = p_ofile+l_loc(l_lng).
ELSE.
ADD 1 TO l_loc.
ENDIF.
ENDWHILE.
Change the local location to the file output
CONCATENATE 'lcd' l_cmd INTO l_cmd SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = v_hdl
command = l_cmd
TABLES
data = t_result
EXCEPTIONS
tcpip_error = 01
command_error = 02
data_error = 03
OTHERS = 04.
IF sy-subrc NE 0.
MESSAGE e200(zhr) WITH 'Unable to issue command:'(021) l_cmd.
ENDIF.
Send a file
CLEAR l_cmd.
CONCATENATE 'put' l_fil INTO l_cmd SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = v_hdl
command = l_cmd
TABLES
data = t_result
EXCEPTIONS
tcpip_error = 01
command_error = 02
data_error = 03
OTHERS = 04.
IF sy-subrc NE 0.
MESSAGE e200(zhr) WITH 'Unable to issue command:'(021) l_cmd.
ELSE.
MESSAGE i200(zhr) WITH text-022. "File FTP'ed to the server.
ENDIF.
ENDFORM. " send_file
&----
*& Form close_ftp_connection
&----
Close the FTP connection
----
FORM close_ftp_connection .
Done! close FTP connection
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = v_hdl.
ENDFORM. " close_ftp_connection
2006 Oct 13 10:21 AM
HI raja and eddy,
thanks for ur answers,
i know we have to call these function modules and the procedure, but my doubt is , in my situation where directory itself is mentioned how to build the ftp_command.
and raja, regarding scrambling pwd, do u have any idea y to do this?
and also it does not seem to be a normal function module it seems to be a cfunc, how to call that?
2006 Oct 13 11:19 AM
2006 Oct 13 11:07 AM
Hi
The way you call a normal FM, the same way (Like how its done in my code)
The purpose of this FM, is to scramble and use the pwd, bcause the pwd (original) should not be known to others, when you try connect to ftp server.
If the directory itself is given, just do a 'lcd' to go to that directory and then do the ftp transfer using 'put'.
Regards,
Raj
2006 Oct 13 11:12 AM
in the pattern if i give the function name, it is giving error.
lcd or cd which should be used?
to use put, we need a file path right?