12-14-2006 6:26 AM
Hi All,
I am trying to run FTP commands from SAP using SAP FM
CALL FUNCTION 'FTP_COMMAND'.
I am ablte to connect to FTP Host and some commands but when I am using its throwing an error - <b>"RFC call of subcommand not implemented" </b>
send <parameter1> <parameter2>
RFC call of subcommand not implemented.
Any inputs what is the error and how to correct it ?
12-16-2006 10:42 AM
Hi
Try this code..
&----
*& Form open_ftp_connection
&----
Open the FTP connection
----
FORM open_ftp_connection .
DATA: l_key TYPE i VALUE 26101957,
l_dstlen TYPE i,
l_rfc LIKE rfcdes-rfcdest.
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.
ENDFORM. " open_ftp_connection
&----
*& 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
Regards,
Raj
12-18-2006 7:48 AM
Thanks Raj.
But I thik code you given works to transfer from one Unix Dir or Other (as you are using put command) and I am looking for transfer from Local PC file to Unix File (send command).
If you have ideas how to do that - From Local to Remote would be greatful.
Are there any other commands using which I can do these trasfers.
Thanks,
Durgesh
Message was edited by:
Durgesh Tiwari
12-18-2006 8:06 AM
Hi,
look in function group SFTP
and sample reports beginning with RSFTP* (package: SFTP)
A.