嵌入式 FTP断点续传原理以及实现指定下载文件起始地址

1、主要这货决定了告诉ftp服务器,我想从文件的什么位置下载:
printf("%s:[%d] restval is %d\n",__FUNCTION__,__LINE__,(int)restval);


/* Decide whether or not to restart.  */
if (opt.always_rest
&& stat (locf, &st) == 0
&& S_ISREG (st.st_mode))  
/* When -c is used, continue from on-disk size.  (Can't use
  hstat.len even if count>1 because we don't want a failed
  first attempt to clobber existing data.)  */
restval = st.st_size;
      else if (count > 1)
restval = len; /* start where the previous run left off */
      else
restval = 0;

printf("%s:[%d] restval is %d\n",__FUNCTION__,__LINE__,(int)restval);


2、主要是这货在ftp.c中决定了是否接续读取服务器上文件:

  printf("%s:[%d] toread is %d\n",__FUNCTION__,__LINE__,(int)toread);
  printf("%s:[%d] startpos is %d\n",__FUNCTION__,__LINE__,(int)startpos);
  printf("%s:[%d] qtyread is %d\n",__FUNCTION__,__LINE__,(int)*qtyread);
  printf("%s:[%d] qtywritten is %d\n",__FUNCTION__,__LINE__,(int)*qtywritten);
  printf("%s:[%d] elapsed is %lf\n",__FUNCTION__,__LINE__,*elapsed);
  


  if (flags & rb_skip_startpos)
    skip = startpos;


  if (opt.verbose)
    {
    printf("%s:[%d] \n",__FUNCTION__,__LINE__);


      /* If we're skipping STARTPOS bytes, pass 0 as the INITIAL
argument to progress_create because the indicator doesn't
(yet) know about "skipping" data.  */
      progress = progress_create (skip ? 0 : startpos, startpos + toread);
      progress_interactive = progress_interactive_p (progress);
    }


  if (opt.limit_rate)
    limit_bandwidth_reset ();


  /* A timer is needed for tracking progress, for throttling, and for
     tracking elapsed time.  If either of these are requested, start
     the timer.  */
  if (progress || opt.limit_rate || elapsed)
    {
      timer = ptimer_new ();
      last_successful_read_tm = 0;
    }


  /* Use a smaller buffer for low requested bandwidths.  For example,
     with --limit-rate=2k, it doesn't make sense to slurp in 16K of
     data and then sleep for 8s.  With buffer size equal to the limit,
     we never have to sleep for more than one second.  */
  if (opt.limit_rate && opt.limit_rate < dlbufsize)
    dlbufsize = opt.limit_rate;


  /* Read from FD while there is data to read.  Normally toread==0
     means that it is unknown how much data is to arrive.  However, if
     EXACT is set, then toread==0 means what it says: that no data
     should be read.  */


  /*alter by kj*/
  //while (!exact || (sum_read < toread))  
  while (sum_read < toread)
  {

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值