‎2008 Dec 19 9:23 AM
Hi Gurus,
There is a need for transferring a file from Application server to a remote server using FTP.
I am able to connect to the remote server and execute commands but the main problem is how do i transfer a file existing in application server as in are there any specific command sthat can be executed using FM FTP_COMMAND (e.g. lcd filepath ).
Please advice.
Many Thanks.
Regards
Saikiran Reddy
Edited by: SAI KIRAN REDDY ARVA on Dec 19, 2008 10:24 AM
Edited by: SAI KIRAN REDDY ARVA on Dec 19, 2008 10:24 AM
‎2008 Dec 19 12:34 PM
Hi,
You might have used ftp_connect to connect to remote server.
Establish FTP connection
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
USER = P_USER
PASSWORD = P_PWD
HOST = P_HOST
RFC_DESTINATION = P_DEST
IMPORTING
HANDLE = LV_HDL.
DATA LV_CMD(250) TYPE C .
CLEAR LV_CMD.
*CONCATENATE 'put' P_FNAME P_FILE INTO LV_CMD*
*SEPARATED BY SPACE.** Establish FTP connection
***P_FNAME --local file name
***P_FILE remote file name
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
HANDLE = lv_HDL
COMMAND = LV_CMD
COMPRESS = 'N'
TABLES
DATA = IT_RESULT
EXCEPTIONS
COMMAND_ERROR = 1
TCPIP_ERROR = 2.
‎2008 Dec 19 2:39 PM
DATA: BEGIN OF MTAB_DATA OCCURS 0
,LINE(132) TYPE C,
END OF MTAB_DATA.
DATA: MC_PASSWORD(20) TYPE C,
MI_KEY TYPE I VALUE 26101957,
MI_PWD_LEN TYPE I,
MI_HANDLE TYPE I.
START-OF-SELECTION.
*-- Your SAP-UNIX FTP password (case sensitive)
MC_PASSWORD = 'password'.
DESCRIBE FIELD MC_PASSWORD LENGTH MI_PWD_LEN IN BYTE MODE.
*-- FTP_CONNECT requires an encrypted password to work
CALL 'AB_RFC_X_SCRAMBLE_STRING'
ID 'SOURCE' FIELD MC_PASSWORD
ID 'KEY' FIELD MI_KEY
ID 'SCR' FIELD 'X'
ID 'DESTINATION' FIELD MC_PASSWORD
ID 'DSTLEN' FIELD MI_PWD_LEN.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
*-- Your SAP-UNIX FTP user name (case sensitive)
USER = 'userid'
PASSWORD = MC_PASSWORD
*-- Your SAP-UNIX server host name (case sensitive)
HOST = 'unix-host'
RFC_DESTINATION = 'SAPFTP'
IMPORTING HANDLE = MI_HANDLE
EXCEPTIONS NOT_CONNECTED = 1
OTHERS = 2.
CHECK SY-SUBRC = 0.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
HANDLE = MI_HANDLE
COMMAND = 'dir'
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.
ELSE.
do some error checking.
WRITE: / 'Error in FTP Command'.
ENDIF.
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
HANDLE = MI_HANDLE
EXCEPTIONS
OTHERS = 1.
cheers
Aveek
‎2008 Dec 22 12:35 PM
Hi,
Using FTP_CONNECT i am able to connect to the remote server but the problem occurs while executing the command using FTP_COMMAND.
I have to transfer a file from application server with the following path
/interface/outbound/test.dat to remote server \import\test.dat
I am getting "error 22 invalid argument"
I am passing CMD = put /interface/outbound/test.dat \import\test.dat
as in put 'sourcerfile' 'targetfile'.
Please advice.
Regards
Saikiran Reddy
‎2008 Dec 23 6:06 AM
Hi,
Once you login to remote server using FTP_CONNECT it will login into default directory.
If you want to change the location of file to be placed from default directory, then you need to use LCD command to change the directory path(before you use put command).
*L_SRC is source directory
CONCATENATE 'lcd' l_src INTO l_com SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = l_com "
TABLES
data = tb_result
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4. "#EC *
Then in your put command just pass the file name, no path is required.
your CMD = put /interface/outbound/test.dat test.dat
put 'sourcerfile' 'targetfile'.
Please try with this ...
Savitha
‎2009 Sep 28 1:52 PM