免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1117 | 回复: 1
打印 上一主题 下一主题

ftp 的socket问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-10-12 17:06 |只看该作者 |倒序浏览
我在linux下用socket实现ftp客户端,对于list这个命令,我代码实现如下
int uc_FtpClient::ListDir()
{
    bool bRet = ftpListen();//实现数据链路的监听
   strCommand = "LIST\r\n";
     bRet = SendCommand( strCommand);
     int nRet = RecvCommandEcho(strMsg); //问题出现在这,
   //strMsg是:“150 here comes the directory listing.\r\n226 Directory send ok\r\n"
     std::cout << strMsg << std::endl; //但前两三次,
   //这里显示:150 here comes the directory listing.\r\n.  
     //226 Directory send ok\r\n 没有显示,两三次后,这句也出现
   bRet = ftpCreateDataChannel();//创建数据传输通道
   long recv_size = RecvData( cBuf, MAX_FILE_LEN );//接收传回来的数据
     std::cout << cBuf << std::endl; //显示接收到的目录信息
   ftpCloseDataListen(); //数据传送通道关闭
   RecvCommandEcho( strMsg ); //再次接收一次命令返回码
   //前两三次,因为,上面的RecvCommandEcho( strMsg );只接收到一句,这句运行良好
   //显示:226 Directory send ok\r\n
    //而且没这一句,第二次运行此函数时,首先接收到的是//226 Directory send ok\r\n
    //并且程序不再正常运行
   //有这句,两三次后,这句在死等,无法继续
}
bool uc_FtpClient::SendCommand(string strCommand)
{
    int bytes_send = send(m_controlSockhd, pcComman, nLen, 0);
    if ( bytes_send != nLen )
    {
        perror("Send command error:");
        return false;
    }
    return true;
}
int uc_FtpClient::RecvCommandEcho(string strMsg)
{
    int bytes_recv = recv(m_controlSockhd, cMsg, MAX_COMMAND_LEN, 0);
    if ( 0 >= bytes_recv )
    {
        perror( "recv command echo error:");
        return -1;
    }
    return bytes_recv;
}

这是我大概的程序,问题在程序中说明,哪位大侠指点一二,谢谢!急

论坛徽章:
38
2017金鸡报晓
日期:2017-02-08 10:39:4215-16赛季CBA联赛之深圳
日期:2023-02-16 14:39:0220周年集字徽章-年
日期:2022-08-31 14:25:28黑曼巴
日期:2022-08-17 18:57:0919周年集字徽章-年
日期:2022-04-25 13:02:5920周年集字徽章-20	
日期:2022-03-29 11:10:4620周年集字徽章-年
日期:2022-03-14 22:35:1820周年集字徽章-周	
日期:2022-03-09 12:51:3220周年集字徽章-年
日期:2022-02-10 13:13:4420周年集字徽章-周	
日期:2022-02-03 12:09:4420周年集字徽章-20	
日期:2022-01-25 20:14:2720周年集字徽章-周	
日期:2022-01-13 15:12:33
2 [报告]
发表于 2006-10-12 17:24 |只看该作者
又来问,答了你也不理,懒的理你了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP