CH395实现FTP_Client例程、抓包和打印log可以在下面的博客中下载
CH395实现FTP_Client应用(上) - lqlq123 - 博客园 (cnblogs.com)
本篇是对例程流程 抓包和打印日志的解析
1.串口打印日志(从上电到流程结束):
1 SourIP: 192,168,3,30, //本地IP 2 CH395FTP Demo 3 CH395FTP Reset 4 CH395Init success 5 CH395 Connect Ethernet 6 Init status : GINT_STAT_PHY_CHANGE 7 sockindex =0 8 TCP Connect //TCP建立成功 21端口 9 sockindex =0 10 len:36 //收到36字节数据 11 MyBuffer: 12 220 Xlight FTP Server 3.9 ready... //36字节所对应的数据内容 13 14 USER :USER WCHNET 15 16 Send:USER WCHNET //发送用户名WCHNET 17 sockindex =0 18 sockindex =0 19 send data success //发送成功 20 sockindex =0 21 len:34 22 MyBuffer: 23 331 Password required for WCHNET //收到应答,需要用户WCHNET对应的密码 24 25 PASS :PASS 123 26 27 Send:PASS 123 //发送密码123 28 sockindex =0 29 sockindex =0 30 send data success 31 sockindex =0 32 len:14 33 MyBuffer: 34 230 Login OK //收到应答,登录成功 35 36 ************ 37 login success 38 ********* 39 TYPE :TYPE A 40 41 Send:TYPE A //指定文件类型:A为ASCII 42 进入目录 43 sockindex =0 44 sockindex =0 45 send data success 46 sockindex =0 47 len:20 48 MyBuffer: 49 200 Type set to A. 50 51 #####PORT :PORT 192,168,3,30,19,237 52 53 Send:PORT 192,168,3,30,19,237 //发送客户端ip和端口,ip为192.168.3.30,端口为19*256+237 = 5101 54 sockindex =0 55 sockindex =0 56 send data success 57 sockindex =0 58 len:29 59 MyBuffer: 60 200 PORT command successful //发送成功 61 62 #####LIST :LIST 63 64 Send:LIST //发送LIST命令 65 sockindex =0 66 sockindex =0 67 send data success //发送成功 68 sockindex =1 //本例程是主动模式,在发送完list命令后,因为要传输数据且已经通过上一个PORT命令告知FTP服务器 客户端(即395)的ip和端口,
所以FTP服务器会主动以源端口20向客户端发起连接请求,395启用socket1与其建立连接 69 TCP Connect 70 TCP Connect 71 sockindex =0 72 len:65 73 MyBuffer: 74 150 Opening ASCII mode data connection for /bin/ls (166 bytes). //发送完list命令后,FTP服务器应答 75 76 #####sockindex =1 77 len:166 78 MyBuffer: 79 drw-rw-rw- 1 ftp ftp 0 Mar 12 10:36 . 80 drw-rw-rw- 1 ftp ftp 0 Dec 22 2023 .. 81 drw-rw-rw- 1 ftp ftp 0 Feb 22 15:35 USER //列出目录 82 83 TCP Disconnect //传输完一次数据后,因为是短连接,所以FTP服务器主动断开数据连接,下次再传输数据时再重新建立新的连接 84 sockindex =0 85 len:37 86 MyBuffer: 87 226 Transfer complete (1.018 KB/s). //本次传输完成 88 89 #####Send:CWD /USER //发送命令进入刚刚所查询到的目录USER 90 sockindex =0 91 sockindex =0 92 send data success 93 sockindex =0 94 len:36 95 MyBuffer: 96 250 Directory successfully changed //进入成功 97 98 #####250^^^^^^^^^^^^^^^^^^^^^^^^^^TYPE :TYPE A 99 100 Send:TYPE A 101 sockindex =0 102 sockindex =0 103 send data success 104 sockindex =0 105 len:20 106 MyBuffer: 107 200 Type set to A. 108 109 #####PORT :PORT 192,168,3,30,19,238 //告知FTP服务器客户端ip和端口 110 111 Send:PORT 192,168,3,30,19,238 112 sockindex =0 113 sockindex =0 114 send data success 115 sockindex =0 116 len:29 117 MyBuffer: 118 200 PORT command successful 119 120 #####LIST :LIST 121 122 Send:LIST 123 sockindex =0 124 sockindex =1 125 TCP Connect 126 TCP Connect 127 sockindex =0 128 send data success 129 sockindex =0 130 len:65 131 MyBuffer: 132 150 Opening ASCII mode data connection for /bin/ls (174 bytes). 133 134 #####sockindex =1 135 len:174 136 MyBuffer: 137 drw-rw-rw- 1 ftp ftp 0 Feb 22 15:35 . 138 drw-rw-rw- 1 ftp ftp 0 Mar 12 10:36 .. 139 -rw-rw-rw- 1 ftp ftp 3 Dec 21 2023 FILELIST.txt //列出目录 140 141 ********* 142 find file 143 ********* 144 TCP Disconnect 145 sockindex =1 146 sockindex =0 147 len:37 148 MyBuffer: 149 226 Transfer complete (1.081 KB/s). 150 151 #####********** 152 search success //成功找到想要的 FILELIST.txt 153 ********* 154 FTP_COMMAND_SUCCESS 155 TYPE :TYPE A 156 157 Send:TYPE A 158 sockindex =0 159 sockindex =0 160 send data success 161 sockindex =0 162 len:20 163 MyBuffer: 164 200 Type set to A. 165 166 SIZE :SIZE FILELIST.txt //SIZE 获取文件信息 167 168 Send:SIZE FILELIST.txt 169 sockindex =0 170 sockindex =0 171 send data success 172 sockindex =0 173 len:7 174 MyBuffer: 175 213 3 //文件数据长度 176 177 PORT :PORT 192,168,3,30,19,239 178 179 Send:PORT 192,168,3,30,19,239 180 sockindex =0 181 sockindex =0 182 send data success 183 sockindex =0 184 len:29 185 MyBuffer: 186 200 PORT command successful 187 188 RETR :RETR FILELIST.txt //RETR 下载文件 189 190 Send:RETR FILELIST.txt 191 sockindex =0 192 sockindex =1 193 TCP Connect 194 TCP Connect 195 sockindex =0 196 send data success 197 sockindex =0 198 len:68 199 MyBuffer: 200 150 Opening ASCII mode data connection for FILELIST.txt (3 bytes). 201 202 sockindex =1 203 len:3 204 MyBuffer: 205 123 //FILELIST.txt中的信息被读取出来 206 TCP Disconnect 207 sockindex =1 208 sockindex =0 209 len:37 210 MyBuffer: 211 226 Transfer complete (0.018 KB/s). 212 213 ********* 214 getfile success //下载文件成功 215 ********* 216 CDUP :CDUP //下载完成后,返回上一级目录 217 218 Send:CDUP 219 sockindex =0 220 sockindex =0 221 send data success 222 sockindex =0 223 len:36 224 MyBuffer: 225 250 Directory successfully changed //目录切换成功 226 227 MKD :MKD TEXT 228 229 Send:MKD TEXT //创建新目录 230 sockindex =0 231 sockindex =0 232 send data success 233 sockindex =0 234 len:28 235 MyBuffer: 236 257 "/" Directory created. 237 238 Send:CWD /TEXT //进入刚刚创建的文件目录 239 240 sockindex =0 241 sockindex =0 242 send data success 243 sockindex =0 244 len:36 245 MyBuffer: 246 250 Directory successfully changed 247 248 TYPE :TYPE A //指定文件类型 249 250 Send:TYPE A 251 sockindex =0 252 sockindex =0 253 send data success 254 sockindex =0 255 len:20 256 MyBuffer: 257 200 Type set to A. 258 259 PORT :PORT 192,168,3,30,19,240 //告知FTP服务器本地ip即下次连接所用的端口 260 261 Send:PORT 192,168,3,30,19,240 262 sockindex =0 263 sockindex =0 264 send data success 265 sockindex =0 266 len:29 267 MyBuffer: 268 200 PORT command successful 269 270 STOR :APPE abc.txt //上传文件,文件名为abc.txt 271 272 Send:APPE abc.txt 273 sockindex =0 274 sockindex =1 275 TCP Connect 276 TCP Connect 277 sockindex =0 278 send data success 279 sockindex =0 280 len:53 281 MyBuffer: 282 150 Opening ASCII mode data connection for abc.txt. 283 284 Send:abcdefghijklmnopqrstuvwxyz0123456789 //将这一串数据写入刚刚创建的abc.txt文本文档中 285 sockindex =0 286 sockindex =1 287 send data success 288 sockindex =0 289 len:37 290 MyBuffer: 291 226 Transfer complete (0.229 KB/s). 292 293 sockindex =1 294 TCP Disconnect 295 ********* 296 putfile success //上传成功 297 ********* 298 QUIT :QUIT //退出FTP服务器 299 300 Send:QUIT 301 sockindex =0 302 sockindex =0 303 send data success 304 len:14 305 MyBuffer: 306 221 Good-Bye 307 308 sockindex =0 309 sockindex =0 310 TCP Disconnect //控制端口21断开连接
2.wireshark抓包
抓包和打印日志流程一致,对照上面的打印日志去解析即可。
标签:FTP,sockindex,success,CH395,len,Client,MyBuffer,send,data From: https://www.cnblogs.com/wchwchlq/p/18068800