CH579M已經(jīng)收到服務(wù)器的log“227 Entering Passive Mode (192,168,2,2,156,38)”并在收到后根據(jù)156*256+38的端口號(hào)創(chuàng)建了新的socket,但沒有后續(xù)的“226 Operation successful”響應(yīng)。而且服務(wù)器端一直顯示“downloading”狀態(tài)。
這是新的socket連接代碼:
void WCHNET_CreateFTPDatClient( UINT16 *DesPort ,UINT16 *SourPort)
{
uint8_t i;
SOCK_INF TmpSocketInf_3;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? uint32_t num = 0; //保存隨機(jī)數(shù)
? ? float down=0,top=999;//區(qū)間范圍
? ? static const int scale = 1;? ? ? ? ? ? ? ??
? ? extern uint16_t MsTick;
? ??
memset((void *)&TmpSocketInf_3,0,sizeof(SOCK_INF));? ? ? ? ? ? ? ? ? ? ? ? ? ?
memcpy((void *)TmpSocketInf_3.IPAddr,mark.ipv4_address,4);? ??
? ? srand((unsigned int)MsTick);//設(shè)置當(dāng)前時(shí)間為隨機(jī)數(shù)種子? ??
? ? num = rand() % ( uint32_t )( ( top - down ) * scale ) + ( uint32_t ) (down * scale);//產(chǎn)生0-999之間的隨機(jī)數(shù),RAND_MAX是生成隨機(jī)數(shù)的最大值? ? ?
? ? *SourPort = 39000 + num;
? ??
? ? TmpSocketInf_3.DesPort =? *DesPort;????//156*256+38的端口號(hào)
? ? TmpSocketInf_3.SourPort = *SourPort;?
? ??
? ? PRINT("\r\nTmpSocketInf_3.DesPort:%d\r\n",TmpSocketInf_3.DesPort);
? ? PRINT("\r\nTmpSocketInf_3.SourPort:%d\r\n",TmpSocketInf_3.SourPort);
? ??
TmpSocketInf_3.ProtoType = PROTO_TYPE_TCP;? ??
? ? TmpSocketInf_3.RecvStartPoint = (UINT32)SocketRecvBuf[1];
? ? TmpSocketInf_3.RecvBufLen = RECE_BUF_LEN ;? ? ? ??
i = WCHNET_SocketCreat(&SocketId3,&TmpSocketInf_3);? ? ? ? ? ? ? ? ? ? ? ? ??
mStopIfError(i);? ?
i =WCHNET_SocketConnect(SocketId3);? ?
? ? mStopIfError(i);? ?
? ??
? ? memset((void *)SocketRecvBuf[SocketId3],'\0',sizeof(SocketRecvBuf[SocketId3]));??
ftp.DatMonitor = SocketId3;
}
這是服務(wù)器端日志:
Info [Type] Message
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 [Response] 220-FileZilla Server 1.6.1
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 [Response] 220 Please visit https://filezilla-project.org/
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 [Command] USER Firmware
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 [Response] 331 Please, specify the password.
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 [Command] PASS ****
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Response] 230 Login successful.
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Command] PWD
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Response] 257 "/" is current directory.
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Command] TYPE I
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Response] 200 Type set to I
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Command] PASV
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Response] 227 Entering Passive Mode (192,168,2,2,152,105)
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Command] MLSD
<27-10-2023 16:29:17> FTP Session 67 192.168.2.45 Firmware [Response] 150 About to start data transfer.