aboutsummaryrefslogtreecommitdiff
path: root/lib/libftp/FtpStor.c
blob: 9cd0e4eb557a067e97943259978e5984cc094bba (plain) (blame)
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
50
51
52
53
54
55
56
57
58
/*
		      Library for ftpd clients.(libftp)
			Copyright by Oleg Orel
			 All rights reserved.

This  library is desined  for  free,  non-commercial  software  creation.
It is changeable and can be improved. The author would greatly appreciate
any  advises, new  components  and  patches  of  the  existing  programs.
Commercial  usage is  also  possible  with  participation of it's author.



*/

#include "FtpLibrary.h"
#include <unistd.h>

STATUS FtpStor (FTP * con , char * command ,
		       char *in , char * out)
{
  FILE *i;
  char buffer[FTPBUFSIZ];
  int size;

  con->seek=0;

  if ( (i=Ftpfopen(in,"rb")) == NULL )
    return EXIT(con,LQUIT);

  if ( FtpTestFlag(con,FTP_REST) &&
      (con->seek=FtpSize(con,out))<0 )
    con->seek=0;


  if ( FtpError(FtpData(con,command,out,"w")))
    {
      if (con->seek==0) return EXIT(con,con->errno);

      con -> seek =0;
      if ( FtpError(FtpData(con,command,out,"w")) )
	return EXIT(con,con->errno);
    }

  if (con->seek) fseek(i,con->seek,0);

  while ( (size=read ( fileno(i) , buffer, FTPBUFSIZ ))>0)
    FtpWriteBlock(con,buffer,size);

  Ftpfclose(i);
  return FtpClose(con);
}