‎2006 Nov 15 5:01 AM
Hi,
I want to FTP txt files to an FTP site ... I have read the blog /people/thomas.jung3/blog/2004/11/15/performing-ftp-commands-from-abap ... I have checked the connection thru SM59 for SAPFTP & SAPFTPA ... it works fine ...
I used prg RSFTP002 using the command pwd and it gave the correct directory name...
I used prg RSFTP004 and an error message came up "Attempt to set up connection failed"
I used RSFTP005 and output is OK for RFC destination SAPFTP & SAPFTPA ..
I donno which parameters to use for prg RSEPSFTP ... so I left it ...
& when I test FM FTP_CONNECT it says "User _____ has no access authorization for computer _______________ "... Please help me what should I do ??
‎2006 Nov 15 5:08 AM
Hi,
If you Find in the WEB or in the Forum, you will get lot of answers for the FTP from ABAP,
REPORT ZFTPSAP LINE-SIZE 132.
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.
*-- 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.
Here are the Some links ..
http://www.guidancetech.com/people/holland/sap/abap/yftp1.htm
Regards
Sudheer
‎2006 Nov 15 5:04 AM
‎2006 Nov 15 5:10 AM
Hi Gopi,
Can you please explain me more in detail ... I have used this FM in one of my previous program ... but that was just to Move or copy file ... how can I use this FM to FTP ??... Please explain
Thank You,
SB.
‎2006 Nov 15 5:08 AM
Hi,
If you Find in the WEB or in the Forum, you will get lot of answers for the FTP from ABAP,
REPORT ZFTPSAP LINE-SIZE 132.
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.
*-- 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.
Here are the Some links ..
http://www.guidancetech.com/people/holland/sap/abap/yftp1.htm
Regards
Sudheer
‎2006 Nov 15 5:17 AM
Hi Sudheer,
the FM 'AB_RFC_X_SCRAMBLE_STRING' is not available in 4.6 C .. but I got a similar FM... HTTP_SCRAAMBLE ... while testing in SE37 what should be the parameters that I should pass to this FM ??
‎2006 Nov 15 5:32 AM
Hi,
There are 2 ways of executing FTP from an ABAP (online or batch mode),
Initiated from the operating system. A script is available in the utility repository that explains how to do this very easily.
Initiated from the ABAP itself An example is given below.
Create a logical OS command 'zftp' using transaction SM69. Make sure that you enable 'command line parameter allowed' checkbox
Create a shell script called 'zftp' with the following lines
RMTHOST=`echo $2 | tr '[A-Z]' '[a-z]'`
ftp -v $RMTHOST << EOF > /out/zftp.$$ 2>&1
lcd /out
put $1
bye
EOF
Use the SXPG_COMMAND_EXECUTE function module to call this script (zftp) with the filename you want to transfer as the parameter. Eg:
call function 'SXPG_COMMAND_EXECUTE'
exporting
commandname =
tables
exec_protocol =
exceptions
no_permission = 1
command_not_found = 2
parameters_too_long = 3
See the Link for an Example program:-
http://www.sapdevelopment.co.uk/fmodules/fms_execom.htm
Regards
Sudheer