CH579M的FTP的被动模式创建了新的socket连接无响应

CH579M已经收到服务器的log“227 Entering Passive Mode (192,168,2,2,156,38)”并在收到后根据156*256+38的端口号创建了新的socket,但没有后续的“226 Operation successful”响应。而且服务器端一直显示“downloading”状态。


这是新的socket连接代码:

void WCHNET_CreateFTPDatClient( UINT16 *DesPort ,UINT16 *SourPort)

{

uint8_t i;

SOCK_INF TmpSocketInf_3;                                                       

    uint32_t num = 0; //保存随机数

    float down=0,top=999;//区间范围

    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);//设置当前时间为随机数种子    

    num = rand() % ( uint32_t )( ( top - down ) * scale ) + ( uint32_t ) (down * scale);//产生0-999之间的随机数,RAND_MAX是生成随机数的最大值     


    *SourPort = 39000 + num;

    

    TmpSocketInf_3.DesPort =  *DesPort;    //156*256+38的端口号

    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;


}

这是服务器端日志:

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.


您好,FTPClient被动模式测试代码,仅供参考(搭配FileZilla测试)。如有问题可邮箱联系(zl@wch.cn)

image.png

icon_rar.gifFTP_Client.zip



好的,谢谢


只有登录才能回复,可以选择微信账号登录