ftp
-
SAP ABAP 与FTP文件交互-进站 文件上传到FTP服务器
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152report z04ftp2.data: begin of ig_ftp_result occurs 0,line(100),end of ig_ftp_result.data: l_path(128) type c. "文件路径,必须以/结尾data: l_filename(128) type c value 'CH210276140222_likp.txt'. "文件名data: l_ftpcommand(100) type c. "FTP命令data: l_handle type i. "HAND"源路径,必须以/结尾data: cons_source(128) type c value '/usr/sap/AA2/D01/data/'.data: cons_dens(128) type c . "目标路径constants cons_key type i value 26101957.data pr_return(1) type c value '0'.*// INITIALIZATIONinitialization.*服务器上下载文件的路径" CONCATENATE '/usr/sap/AA2/D01/data/' INTO cons_source.*// START OF SELECTIONstart-of-selection.perform frm_ftp_file.form frm_ftp_file .data:l_dstlen type i, "DESTINATION LENl_pw(64) type c. "密码长度一定要够否则出错* 连接FTP服务器l_pw = 'sap888'.*-- FTP_CONNECT requires an encrypted password to work* CREATE THE NEW PW BASE ON LOGIN FTP PASS WORD.call function 'HTTP_SCRAMBLE'exportingsource = l_pwsourcelen = 6key = cons_keyimportingdestination = l_pw.do 3 times." 连接三次,以为一次可能会不成功* OPEN THE FTP SERVER.call function 'FTP_CONNECT'exportinguser = 'sap01' "USERpassword = l_pw "PASS WORDhost = '9.186.155.115 9980'rfc_destination = 'SAPFTPA' "DEFAULTimportinghandle = l_handleexceptionsnot_connected = 1others = 2.if sy-subrc = 0.exit.endif.enddo.if sy-subrc <> 0.write :/ sy-datum, sy-uzeit, sy-uname, 'CONNECT FTP FAILED!'. "MESSAGEGstop.endif.* Change local directoryclear l_ftpcommand.concatenate 'lcd' cons_source into l_ftpcommand separated by space.perform frm_ftp_command using l_ftpcommand pr_return.if pr_return = '1'.write:/ sy-datum, sy-uzeit, sy-uname, 'FTP改变本地路径错误!'.stop.endif.* Change ftp directoryif cons_dens <> ''.clear l_ftpcommand.concatenate 'cd' cons_dens into l_ftpcommand separated by space.perform frm_ftp_command using l_ftpcommand pr_return.endif.* Change TRANSFER MODEclear l_ftpcommand.* l_ftpcommand = 'binary'.l_ftpcommand = 'ascii'.perform frm_ftp_command using l_ftpcommand pr_return.if pr_return = '1'.write:/ sy-datum, sy-uzeit, sy-uname, '改变FTP传输模式出现错误!'.stop.endif.* Put File into FTP SERVERclear l_ftpcommand.concatenate 'put' l_filename into l_ftpcommand separated by space.perform frm_ftp_command using l_ftpcommand pr_return.if pr_return = '1'.write:/ sy-datum, sy-uzeit, sy-uname, '文件传输中出现错误!'.stop.endif.* 断开FTP服务器call function 'FTP_DISCONNECT'exportinghandle = l_handle.write:/ sy-datum, sy-uzeit, sy-uname, '文件传输成功!'.endform. " FRM_FTP_FILE*************************************************************************& FORM FRM_FTP_COMMAND **************************************************************************& FTP Command *************************************************************************form frm_ftp_command using pr_command pr_ret.call function 'FTP_COMMAND'exportinghandle = l_handlecommand = pr_command* COMPRESS =* RFC_DESTINATION =* VERIFY =* IMPORTING* FILESIZE =* FILEDATE =* FILETIME =tablesdata = ig_ftp_resultexceptionstcpip_error = 1command_error = 2data_error = 3others = 4.* Disconnectif sy-subrc <> 0." 调用中出错立即断开连接pr_ret = '1'.call function 'FTP_DISCONNECT'exportinghandle = l_handle.exit.endif.endform. "FRM_FTP_COMMAND -
ABAP连接FTP并执行Command
123456789101112131415161718192021222324252627282930313233343536373839404142434445See ht e coding below, I have used these Fm to connect to FTP server and get the Files..*types for the ftp command result internal tableTYPES : BEGIN OF ty_result,text TYPE char512,END OF ty_result.data it_result type standard table of ty_result.*Connect to the FTP serverCALL FUNCTION 'FTP_CONNECT'EXPORTINGuser = lv_user " user name pass word to connectpassword = l_v_pwdhost = 'dev.eu.pm.com' " Host name hererfc_destination = 'SAPFTPA' "destination name*Ask your functional people for the above dataIMPORTINGhandle = v_handleEXCEPTIONSnot_connected = 1OTHERS = 2.IF sy-subrc <> 0.ENDIF.*Changing directoryCONCATENATE 'cd' '<file path>' INTO l_v_cmd SEPARATED BY space.you can also ser 'DIR in l_v_cmd which opens the directory and all the folders *get into it_result table..*Execute the FTP CommandCALL FUNCTION 'FTP_COMMAND'EXPORTINGhandle = v_handlecommand = l_v_cmdTABLESdata = it_resultEXCEPTIONStcpip_error = 1command_error = 2data_error = 3OTHERS = 4.IF sy-subrc <> 0.ENDIF. -
SAP ABAP FTP操作
FTP到文件服务器,服务器上文件读写
-
[转]FTP服务器和ABAP的连接
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196*&---------------------------------------------------------------------**& Report ZLITEST*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT zlitest.TYPE-POOLS:slis,truxs.TABLES: mseg,mkpf,makt,ekko,mara.DATA: l_ftpcommand(128) TYPE c. "FTP commandDATA: l_handle TYPE i. "HANDleDATA: pr_return TYPE c.DATA lt_ftp TYPE truxs_t_text_data.DATA ls_ftp TYPE truxs_t_text_data WITH HEADER LINE.DATA: hdl TYPE i,key TYPE i VALUE 26101957,slen TYPE i.DATA dest LIKE rfcdes-rfcdest VALUE 'SAPFTP'.DATA:l_file_name(30) TYPE c.DATA:l_path(255) TYPE c.DATA:l_file(255) TYPE c.DATA: BEGIN OF lt_output OCCURS 0,name(10) TYPE c,age(2) TYPE n,address(20) TYPE c,END OF lt_output.DATA:lt_output_ftp LIKE TABLE OF lt_output WITH HEADER LINE.DATA pv_pw(30) TYPE c.lt_output-name = 'LIYUWU'.lt_output-age = 24.lt_output-address = 'hunang yongzhou'.APPEND lt_output.lt_output-name = 'FANGCHUN'.lt_output-age = 22.lt_output-address = 'shichuan'.APPEND lt_output.LOOP AT lt_output.MOVE-CORRESPONDING lt_output TO lt_output_ftp.APPEND lt_output_ftp.CLEAR lt_output_ftp.ENDLOOP.l_file_name = 'ftcput.txt'.CALL FUNCTION 'FILE_GET_NAME'EXPORTINGclient = sy-mandtlogical_filename = 'ZFTOSHIBA'operating_system = sy-opsyseleminate_blanks = 'X'IMPORTINGfile_name = l_pathEXCEPTIONSfile_not_found = 1OTHERS = 2.CONCATENATE l_path l_file_name INTO l_file.TRANSLATE l_file TO LOWER CASE.**CALL FUNCTION 'ZTRANSVMI_FILE_TO_FTP'* EXPORTING* pv_path = l_file* pv_host = '10.10.11.131'* pv_user = 'ittest'* pv_pw = 'abcd!1234'* pv_ftppath = 'toshiba\vmi\put'* pv_ftpfn = 'miput.TXT'** IMPORTING** PV_SUBRC =* TABLES* pv_tbl = lt_output_ftp* .CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'EXPORTINGi_field_seperator ='|'* I_LINE_HEADER =* I_FILENAME =* I_APPL_KEEP = ' 'TABLESi_tab_sap_data = lt_output_ftpCHANGINGi_tab_converted_data = lt_ftpEXCEPTIONSconversion_failed = 1OTHERS = 2.IF sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.OPEN DATASET l_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.IF sy-subrc EQ 0.LOOP AT lt_ftp INTO ls_ftp.TRANSFER ls_ftp TO l_file.ENDLOOP.ENDIF.CLOSE DATASET l_file.slen = STRLEN( 'abcd!1234' ) .DO 10 TIMES.CALL FUNCTION 'HTTP_SCRAMBLE'EXPORTINGSOURCE = 'abcd!1234'sourcelen = slenkey = keyIMPORTINGdestination = pv_pw.CALL FUNCTION 'FTP_CONNECT'EXPORTINGuser = 'ittest'password = pv_pw* ACCOUNT =host = '10.10.11.131'rfc_destination = dest* GATEWAY_USER =* GATEWAY_PASSWORD =* GATEWAY_HOST =IMPORTINGhandle = hdl.* EXCEPTIONS* NOT_CONNECTED = 1* OTHERS = 2.IF sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.EXIT.ENDIF.ENDDO.CLEAR l_ftpcommand.CONCATENATE 'cd' 'TOSHIBA\VMI\PUT' INTO l_ftpcommand SEPARATED BY space.perform frm_ftp_command using l_ftpcommandchanging pr_return hdl.clear l_ftpcommand.l_ftpcommand = 'ascii'.perform frm_ftp_command using l_ftpcommandchanging pr_return hdl.clear l_ftpcommand.concatenate 'put' l_file 'liyutest.txt'into l_ftpcommand separated by space.perform frm_ftp_command using l_ftpcommandchanging pr_returnhdl.*&---------------------------------------------------------------------**& Form frm_ftp_command*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->PV_COMMAND text* -->CHANGE text* -->PV_RET text* -->PV_HANDLE text*----------------------------------------------------------------------*FORM frm_ftp_command USING pv_command changing pv_ret pv_handle.DATA:BEGIN OF it_result OCCURS 0,line(100) TYPE c,END OF it_result.CALL FUNCTION 'FTP_COMMAND'EXPORTINGhandle = pv_handlecommand = pv_commandcompress = 'N'TABLESdata = it_resultEXCEPTIONStcpip_error = 1command_error = 2data_error = 3.IF sy-subrc <> 0.pv_ret = '1'.CALL FUNCTION'FTP_DISCONNECT'EXPORTINGhandle = pv_handle.EXIT.ENDIF.ENDFORM. "frm_ftp_command -
将SAP数据传输到其他系统
如何将SAP数据传输到其他系统(Transferring Data from SAP to Other Systems) 在sap里有GUI_DOWNLOAD 函数将sap的数据下…