1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
report 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'. *// INITIALIZATION initialization. *服务器上下载文件的路径 " CONCATENATE '/usr/sap/AA2/D01/data/' INTO cons_source. *// START OF SELECTION start-of-selection. perform frm_ftp_file. form frm_ftp_file . data: l_dstlen type i, "DESTINATION LEN l_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' exporting source = l_pw sourcelen = 6 key = cons_key importing destination = l_pw. do 3 times." 连接三次,以为一次可能会不成功 * OPEN THE FTP SERVER. call function 'FTP_CONNECT' exporting user = 'sap01' "USER password = l_pw "PASS WORD host = '9.186.155.115 9980' rfc_destination = 'SAPFTPA' "DEFAULT importing handle = l_handle exceptions not_connected = 1 others = 2. if sy-subrc = 0. exit. endif. enddo. if sy-subrc <> 0. write :/ sy-datum, sy-uzeit, sy-uname, 'CONNECT FTP FAILED!'. "MESSAGEG stop. endif. * Change local directory clear 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 directory if 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 MODE clear 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 SERVER clear 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' exporting handle = 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' exporting handle = l_handle command = pr_command * COMPRESS = * RFC_DESTINATION = * VERIFY = * IMPORTING * FILESIZE = * FILEDATE = * FILETIME = tables data = ig_ftp_result exceptions tcpip_error = 1 command_error = 2 data_error = 3 others = 4 . * Disconnect if sy-subrc <> 0." 调用中出错立即断开连接 pr_ret = '1'. call function 'FTP_DISCONNECT' exporting handle = l_handle. exit. endif. endform. "FRM_FTP_COMMAND |
本文作者: GavinDong
版权属于: GavinDong博客
文章链接: https://gavindong.com/1692.html
如果使用过程中遇到问题,可 **点击此处** 交流沟通。
版权所有,转载时必须以链接形式注明作者和原始出处及本声明。