Sunday, December 26, 2010
*&--------------------------------------------------------------------- *& Report ZFTP_CONNECT *& *&--------------------------------------------------------------------- REPORT zftp_connect. DATA: BEGIN OF mtab_data OCCURS 0, line(132) TYPE c, END OF mtab_data. DATA: BEGIN OF mtab_data1 OCCURS 0, line(132) TYPE c, END OF mtab_data1. DATA : error TYPE string. DATA: mc_password(20) TYPE c, err(20) TYPE c, mi_key TYPE i VALUE 26101957, mi_pwd_len TYPE i, mi_handle TYPE i. DATA: mat TYPE bapimatall. DATA: lv_user(30) TYPE c, lv_pwd(30) TYPE c , lv_host(64) TYPE c, iv_file_path(20) TYPE c, cmd(120). DATA: lv_dest TYPE rfcdes-rfcdest. START-OF-SELECTION. CALL FUNCTION 'FTP_CONNECT' EXPORTING user = lv_user "Your SAP-UNIX FTP user name (case sensitive) password = lv_pwd "Your SAP-UNIX server host name (case sensitive) host = '172.20.15.73' rfc_destination = 'SAPFTP' IMPORTING handle = mi_handle EXCEPTIONS not_connected = 1 OTHERS = 2. CHECK sy-subrc = 0. cmd = 'cd \Material" "Master'. *--This is sender directory path *--Note down that if there is space in directory name it can be handled by " " *--command cd \Material master will generate error PERFORM ftp_command USING cmd. cmd = 'ascii'. *--FTP transfers are generally performed in either ASCII or binary mode. Binary mode is the preferred mode to transfer non-text files. ASCII mode is the preferred mode to transfer text files. PERFORM ftp_command USING cmd. cmd = 'lcd d:\ftp'. "This is target directory path on local machine PERFORM ftp_command USING cmd. cmd = 'ls'. "list all the files available under source folder PERFORM ftp_command USING cmd. * mtab_data contains file names of all files under source folder LOOP AT mtab_data FROM 2. CONCATENATE 'get' mtab_data+39(80) INTO cmd SEPARATED BY space. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = mi_handle command = cmd TABLES data = mtab_data1 EXCEPTIONS tcpip_error = 1 command_error = 2 data_error = 3 OTHERS = 4. IF sy-subrc = 0. LOOP AT mtab_data1. WRITE: / mtab_data1. ENDLOOP. ELSE. * do some error checking. CONCATENATE 'Error in FTP Command while executing' cmd INTO error SEPARATED BY space. WRITE: / error. ENDIF. CLEAR mtab_data1[]. CONCATENATE 'delete' mtab_data+39(80) INTO cmd SEPARATED BY space. PERFORM ftp_command USING cmd. * IF you WANT delete FILE after copy command you can run delete command ENDLOOP. CLEAR mtab_data[]. *--Disconnect from FTP server CALL FUNCTION 'FTP_DISCONNECT' EXPORTING handle = mi_handle EXCEPTIONS OTHERS = 1. *--Close RFC connection CALL FUNCTION 'RFC_CONNECTION_CLOSE' EXPORTING destination = 'SAPFTP' EXCEPTIONS OTHERS = 1. *&---------------------------------------------------------------------* *& Form ftp_command *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_CMD text *----------------------------------------------------------------------* FORM ftp_command USING p_cmd. CALL FUNCTION 'FTP_COMMAND' EXPORTING handle = mi_handle command = p_cmd 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. IF p_cmd <> 'ls'. CLEAR mtab_data[]. ENDIF. ENDFORM. " ftp_command
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Sending email with pdf attachment
- ABAP - Step by step tutorial on Smart Forms - Template Node
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
0 comments:
Post a Comment
Your useful comments, suggestions are appreciated.Your comments are moderated.