~peter-pearse/ubuntu/natty/lftp/prop001

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <config.h>
#include <unistd.h>
#include "FileAccess.h"
#include "log.h"

char *program_name;

int main(int argc,char **argv)
{
   program_name=argv[0];

   Log::global->SetOutput(2,false);
   Log::global->SetLevel(5);
   Log::global->Enable();
   Log::global->ShowNothing();

   FileAccess *f=FileAccess::New("http","ftp.yar.ru");
   if(!f)
   {
      fprintf(stderr,"http: unknown protocol, cannot create http session\n");
      return 1;
   }
   f->Open("/pub/source/lftp/",f->RETRIEVE);
   for(;;)
   {
      SMTask::Schedule();

      char buf[1024];
      int res=f->Read(buf,sizeof(buf));
      if(res<0)
      {
	 if(res==f->DO_AGAIN)
	 {
	    SMTask::Block();
	    continue;
	 }
	 fprintf(stderr,"Error: %s\n",f->StrError(res));
	 return 1;
      }
      if(res==0) // eof
      {
	 f->Close();
	 return 0;
      }
      write(1,buf,res);
   }
   SMTask::Delete(f);
   return 0;
}