ftp client的问题

Jorn 2009-06-08 06:01:15
在vxworks下一个ftpclient程序,需要支持断点续传。现在有个问题是怎么判断client端与server端的意外网络中断。我写的实验室代码如下:(还没有加断点续传的东西,很简单的测试)。
if ((ctrlSock = ftpHookup(UNIX_HOST)) == ERROR)
{
perror("ftpHookup error!") ;
return ERROR ;
}
if ((ftpLogin (ctrlSock, USER, PASSWD, "") == ERROR))
{
perror("ftpLogin error!") ;
return ERROR ;
}

if (( ftpCommand (ctrlSock, "TYPE I", 0, 0, 0, 0, 0, 0)) != FTP_COMPLETE)
{
perror ("TYPE FTP command positive completion failed");
}

if (( ftpCommand (ctrlSock, "CWD ", 0, 0, 0, 0, 0, 0)) != FTP_COMPLETE)
{
perror ("TYPE FTP command positive completion failed");
}

if ((dataSock = ftpDataConnInit(ctrlSock)) == ERROR)
{
perror("ftpDataConnInit error") ;
}

if ((i = ftpCommand (ctrlSock, "REST %d", 1000, 0, 0, 0, 0, 0)) != FTP_COMPLETE)
{
perror ("LIST FTP command positive completion failed");
}

if ((i = ftpCommand (ctrlSock, "RETR %s", fileName, 0, 0, 0, 0, 0)) != FTP_COMPLETE)
{
perror ("LIST FTP command positive completion failed");
}

if ((dataSock = ftpDataConnGet(dataSock)) == ERROR)
{
perror("ftpDataConnGet error") ;
}


while( (numBytes = read(dataSock,cc, sizeof(cc) )) > 0)
{
i += numBytes ;
printf("i = %d \n" , i ) ;


}

close(dataSock);
printf("i = %d \n" , i);

if (ftpCommand (ctrlSock, QUIT_CMND, 0, 0, 0, 0, 0, 0) != FTP_COMPLETE)
{
perror ("QUIT FTP command positive completion failed");
return (ERROR);
}
close (ctrlSock);

return OK;

以拔掉网线作为意外的网络中断事件,每次拔掉网线后,程序就在红色代码处阻塞。请问怎么解决这个问题。

只要能判断意外的网络中断事件。




...全文
208 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
evoleci 2009-06-11
  • 打赏
  • 举报
回复
是不是加个接收缓冲区,然后针对数据包的包头包尾来做判断好一点儿呢?
Jorn 2009-06-09
  • 打赏
  • 举报
回复
呼唤斑竹。。
Jorn 2009-06-09
  • 打赏
  • 举报
回复
???
no one know???

2,180

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧