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 exist
|
|
|
|
ing 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>
|
|
|
|
#include <ctype.h>
|
1995-04-25 15:05:11 +00:00
|
|
|
|
|
|
|
char * FtpPasv (FTP *ftp)
|
|
|
|
{
|
|
|
|
char *msg;
|
1995-05-13 22:09:52 +00:00
|
|
|
static String PORT;
|
1995-04-25 15:05:11 +00:00
|
|
|
char *p=PORT;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
|
|
|
if FtpError(FtpCommand(ftp,"PASV","",227,EOF))
|
1995-04-25 15:05:11 +00:00
|
|
|
return "";
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
msg = FtpMessage (227);
|
|
|
|
|
|
|
|
msg+=3;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
|
|
|
while (!isdigit(*msg++));
|
1995-04-25 15:05:11 +00:00
|
|
|
msg--;
|
|
|
|
|
|
|
|
while (isdigit(*msg)||*msg==',') *p++=*msg++;
|
|
|
|
*p=0;
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
return PORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
STATUS FtpLink(FTP *ftp1, FTP *ftp2)
|
|
|
|
{
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
String PORT;
|
|
|
|
|
|
|
|
strcpy(PORT,FtpPasv(ftp1));
|
|
|
|
|
|
|
|
FtpCommand(ftp2,"PORT %s",PORT,200,EOF);
|
1995-04-25 15:08:02 +00:00
|
|
|
return 0;
|
1995-04-25 15:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STATUS FtpPassiveTransfer(FTP *ftp1, FTP *ftp2, char *f1, char *f2)
|
|
|
|
{
|
|
|
|
String tmp;
|
|
|
|
fd_set fds;
|
|
|
|
|
|
|
|
FtpAssert(ftp1,FtpLink(ftp1,ftp2));
|
|
|
|
|
|
|
|
|
|
|
|
if (!*f2) f2=f1;
|
|
|
|
|
|
|
|
FtpAssert(ftp2,FtpCommand(ftp2,"STOR %s",f2, 200, 120 , 150 , 125 , 250 , EOF ));
|
|
|
|
FtpAssert(ftp1,FtpCommand(ftp1,"RETR %s",f1, 200, 120 , 150 , 125 , 250 , EOF ));
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
FD_ZERO(&fds);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
FD_SET(fileno(FTPCMD(ftp1)),&fds);
|
|
|
|
FD_SET(fileno(FTPCMD(ftp2)),&fds);
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
if (select(getdtablesize(),&fds,0,0,0)<0)
|
|
|
|
{
|
|
|
|
if (ftp1->error!=NULL)
|
|
|
|
return (*(ftp1->error))(ftp1,QUIT,sys_errlist[errno]);
|
|
|
|
if (ftp2->error!=NULL)
|
|
|
|
return (*(ftp2->error))(ftp1,QUIT,sys_errlist[errno]);
|
|
|
|
return QUIT;
|
|
|
|
}
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1995-04-25 15:05:11 +00:00
|
|
|
if (FD_ISSET(fileno(FTPCMD(ftp1)),&fds))
|
|
|
|
{
|
|
|
|
FtpGetMessage(ftp1,tmp);
|
|
|
|
FtpLog(ftp1->title,tmp);
|
|
|
|
FtpGetMessage(ftp2,tmp);
|
|
|
|
FtpLog(ftp2->title,tmp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FtpGetMessage(ftp2,tmp);
|
|
|
|
FtpLog(ftp2->title,tmp);
|
|
|
|
FtpGetMessage(ftp1,tmp);
|
|
|
|
FtpLog(ftp1->title,tmp);
|
|
|
|
}
|
1995-04-25 15:08:02 +00:00
|
|
|
return 0;
|
1995-04-25 15:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|