示例#1
0
文件: ftp.c 项目: hoangduit/reactos
/*VARARGS1*/
int command(const char *fmt, ...)
{
	va_list ap;
	int r;
	void (*oldintr)(int);

	abrtflag = 0;
	if (debug) {
		printf("---> ");
		va_start(ap, fmt);
		vfprintf(stdout, fmt, ap);
		va_end(ap);
		printf("\n");
		(void) fflush(stdout);
	}
	if (cout == 0) {
		perror ("No control connection for command");
		code = -1;
		return (0);
	}
	oldintr = signal(SIGINT,cmdabort);
	{
		char buffer[1024];

		va_start(ap, fmt);
		vsprintf(buffer, fmt, ap);
		va_end(ap);
//DLJ: to work through  firewalls - send the command as a single message
		strcat(buffer,"\r\n");
		fprintfSocket(cout, buffer);
	}
//DLJ: the following two lines are replaced by the strcat above - seems to
// make it work through firewalls.
//	fprintfSocket(cout, "\r\n");
//	(void) fflush(cout);
	cpend = 1;
	r = getreply(!strcmp(fmt, "QUIT"));
	if (abrtflag && oldintr != SIG_IGN)
		(*oldintr)(SIGINT);
//	(void) signal(SIGINT, oldintr);
	return(r);
}
示例#2
0
/*
  WarFTP
  |->âABOR
  |<-226 Transfer complete. 39600000 bytes in 18.84 sec. (2052.974 Kb/s)
  |<-225 ABOR command successful.

  FreeBSD, SunOS
  |->òABOR
  |<-426 Transfer aborted. Data connection closed.
  |<-226 Abort successful

  QNX
  |->âABOR
  |<-226 Transfer complete.
  |<-225 ABOR command successful.

  IIS
  |->âABOR
  |<-225 ABOR command successful.

  QNX
  |->òABOR
  |<-452 Error writing file: No child processes.
  |<-225 ABOR command successful.

  GuildFTP (have no ABOR notify at all)
  -> <ABORT>
  <- 226 Transfer complete. 11200000 bytes in 2 sec. (5600.00 Kb/s).

  ??
  ->òABOR
  <-450 Transfer aborted. Link to file server lost.
  <-500 ÿôÿòABOR not understood
*/
BOOL Connection::SendAbort(SOCKET din)
{
	do
	{
		if(!fprintfSocket(cout,"%c%c",ffIAC,ffIP))
		{
			Log(("!send ffIAC"));
			break;
		}

		char msg = ffIAC;

		/* send ffIAC in urgent mode instead of DM because UNIX places oob mark */
		/* after urgent byte rather than before as now is protocol            */
		if(nb_send(&cout,&msg,1,MSG_OOB) != 1)
		{
			Log(("rr: !send urgent"));
			break;
		}

		if(!fprintfSocket(cout,"%cABOR\r\n",ffDM))
		{
			Log(("!send ABOR"));
			break;
		}

		scClose(data_peer,-1);
		int res;
		Log(("Wait ABOT reply"));
		res = getreply(FALSE);

		if(res == RPL_TIMEOUT)
		{
			Log(("Error waiting first ABOR reply"));
			return FALSE;
		}

		//Single line
		if(code == 225)
		{
			Log(("Single line ABOR reply"));
			return TRUE;
		}
		else

			//Wait OPTIONAL second line
			if(code == 226)
			{
				Log(("Wait OPT second reply"));

				do
				{
					res = getreply(FALSE,500);

					if(res == RPL_TIMEOUT)
					{
						Log(("Timeout: res: %d, code: %d", res, code));
						return TRUE;
					}
					else if(res == RPL_ERROR)
					{
						Log(("Error: res: %d, code: %d", res, code));
						return FALSE;
					}

					Log(("Result: res: %d, code: %d", res, code));
				}
				while(true);
			}
			else
			{
				//Wait second line
				Log(("Wait second reply"));
				res = getreply(FALSE);

				if(res == RPL_TIMEOUT)
				{
					Log(("Error waiting second ABOR reply"));
					return FALSE;
				}

				Log(("Second reply: res: %d, code: %d", res,code));
				return TRUE;
			}
	}
	while(0);  /*Error sending ABOR*/

	return FALSE;
}