1995-04-25 15:05:11 +00:00
|
|
|
/*
|
|
|
|
Library for ftpd clients.(libftp)
|
|
|
|
Copyright by Oleg Orel
|
|
|
|
All rights reserved.
|
1995-05-30 05:51:47 +00:00
|
|
|
|
|
|
|
This library is desined for free, non-commercial software creation.
|
|
|
|
It is changeable and can be improved. The author would greatly appreciate
|
1995-04-25 15:05:11 +00:00
|
|
|
any advises, new components and patches of the existing programs.
|
|
|
|
Commercial usage is also possible with participation of it's author.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "FtpLibrary.h"
|
1995-04-25 15:08:02 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
extern STATUS FtpFilenameChecker(char ** in, char ** out);
|
1995-04-25 15:05:11 +00:00
|
|
|
|
|
|
|
STATUS FtpRetr (FTP * con , char * command ,
|
|
|
|
char *in , char * out)
|
|
|
|
{
|
|
|
|
FILE *o;
|
|
|
|
struct stat st;
|
1995-04-25 15:08:02 +00:00
|
|
|
char buffer[FTPBUFSIZ];
|
1995-04-25 15:05:11 +00:00
|
|
|
register int size;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
FtpFilenameChecker(&in,&out);
|
|
|
|
|
|
|
|
if ( FtpTestFlag(con,FTP_REST) && stat(out,&st)==0)
|
|
|
|
{
|
|
|
|
con -> seek = st.st_size;
|
|
|
|
if ((o=Ftpfopen(out,"a+"))==NULL)
|
|
|
|
return EXIT(con,LQUIT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
con -> seek = 0;
|
|
|
|
if ((o=Ftpfopen(out,"w+"))==NULL)
|
|
|
|
return EXIT(con,LQUIT);
|
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
|
|
|
|
if ( FtpError(FtpData(con,command,in,"r")))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (con->seek==0) return EXIT(con,con->errno);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
con -> seek = 0;
|
|
|
|
fclose(o);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
if ( FtpError(FtpData(con,command,in,"r")) )
|
|
|
|
{
|
|
|
|
return EXIT(con,con->errno);
|
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
if ((o=Ftpfopen(out,"w+"))==NULL)
|
|
|
|
return EXIT(con,LQUIT);
|
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
fseek(o,con->seek,0);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
while((size=FtpReadBlock(con,buffer,FTPBUFSIZ))>0)
|
|
|
|
{
|
|
|
|
if (write(fileno(o),buffer,size)!=size)
|
|
|
|
return EXIT(con,LQUIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ftpfclose(o);
|
|
|
|
return FtpClose(con);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|