freebsd-skq/lib/libftp/FtpPasv.c

101 lines
1.9 KiB
C
Raw Normal View History

/* 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
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"
#include <unistd.h>
#include <ctype.h>
char * FtpPasv (FTP *ftp)
{
char *msg;
static String PORT;
char *p=PORT;
1995-05-30 05:51:47 +00:00
if FtpError(FtpCommand(ftp,"PASV","",227,EOF))
return "";
1995-05-30 05:51:47 +00:00
msg = FtpMessage (227);
msg+=3;
1995-05-30 05:51:47 +00:00
while (!isdigit(*msg++));
msg--;
while (isdigit(*msg)||*msg==',') *p++=*msg++;
*p=0;
1995-05-30 05:51:47 +00:00
return PORT;
}
STATUS FtpLink(FTP *ftp1, FTP *ftp2)
{
1995-05-30 05:51:47 +00:00
String PORT;
strcpy(PORT,FtpPasv(ftp1));
FtpCommand(ftp2,"PORT %s",PORT,200,EOF);
return 0;
}
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
FD_ZERO(&fds);
1995-05-30 05:51:47 +00:00
FD_SET(fileno(FTPCMD(ftp1)),&fds);
FD_SET(fileno(FTPCMD(ftp2)),&fds);
1995-05-30 05:51:47 +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
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);
}
return 0;
}