예제 #1
0
파일: ftpsend.c 프로젝트: sebastinas/yafc
/* abort routine originally from Cftp by Dieter Baron
 */
int ftp_abort(Socket* fp)
{
	char buf[4096];

#ifdef HAVE_LIBSSH
	if(ftp->session)
		/* FIXME: what? */
		return 0;
#endif

	if(!ftp_connected())
		return -1;

	ftp_set_close_handler();

	if (sock_check_pending(fp, false) == 1) {
		ftp_trace("There is data on the control channel, won't send ABOR\n");
		/* read remaining bytes from connection */
		while(fp && sock_read(fp, buf, sizeof(buf)) > 0)
			/* LOOP */ ;
		return 0;
	}

	ftp->ti.interrupted = true;
	ftp_err(_("Waiting for remote to finish abort...\n"));

	ftp_trace("--> telnet interrupt\n");
	if(sock_telnet_interrupt(ftp->ctrl) != 0)
		ftp_err("telnet interrupt: %s\n", strerror(errno));

	/* ftp_cmd("ABOR") won't work here,
	 * we must flush data between the ABOR command and ftp_read_reply()
	 */
	sock_krb_printf(ftp->ctrl, "ABOR");
	sock_printf(ftp->ctrl, "\r\n");
	sock_flush(ftp->ctrl);
	if(ftp_get_verbosity() == vbDebug)
		ftp_err("--> [%s] ABOR\n", ftp->url->hostname);
	else
		ftp_trace("--> [%s] ABOR\n", ftp->url->hostname);

    /* read remaining bytes from connection */
	while(fp && sock_read(fp, buf, sizeof(buf)) > 0)
		/* LOOP */ ;

	/* we expect a 426 or 226 reply here... */
	ftp_read_reply();
	if(ftp->fullcode != 426 && ftp->fullcode != 226)
		ftp_trace("Huh!? Expected a 426 or 226 reply\n");

	/* ... and a 226 or 225 reply here, respectively */
	/* FIXME: should skip this reply if prev. reply wasn't 426 or 226 ? */
	ftp_read_reply();
	if(ftp->fullcode != 226 && ftp->fullcode != 225)
		ftp_trace("Huh!? Expected a 226 or 225 reply\n");

	return -1;
}
예제 #2
0
파일: ftpsend.c 프로젝트: wmene/yafc-1.1.2
/* abort routine originally from Cftp by Dieter Baron
 */
int ftp_abort(FILE *fp)
{
    char buf[4096];
    fd_set ready;
    struct timeval poll;

    if(ftp->ssh_pid)
        /* FIXME: what? */
        return 0;

    if(!ftp_connected())
        return -1;

    ftp_set_close_handler();

    poll.tv_sec = poll.tv_usec = 0;
    FD_ZERO(&ready);
    FD_SET(ftp->ctrl->handle, &ready);
    if(select(ftp->ctrl->handle+1, &ready, 0, 0, &poll) == 1) {
        ftp_trace("There is data on the control channel, won't send ABOR\n");
        /* read remaining bytes from connection */
        while(fp && fread(buf, 1, 4096, fp) > 0)
            /* LOOP */ ;
        return 0;
    }

    ftp->ti.interrupted = true;
    ftp_err(_("Waiting for remote to finish abort...\n"));

    ftp_trace("--> telnet interrupt\n");
    if(sock_telnet_interrupt(ftp->ctrl) != 0)
        ftp_err("telnet interrupt: %s\n", strerror(errno));

    /* ftp_cmd("ABOR") won't work here,
     * we must flush data between the ABOR command and ftp_read_reply()
     */
    sock_krb_printf(ftp->ctrl, "ABOR");
    sock_printf(ftp->ctrl, "\r\n");
    sock_flush(ftp->ctrl);
    if(ftp_get_verbosity() == vbDebug)
        ftp_err("--> [%s] ABOR\n", ftp->url->hostname);
    else
        ftp_trace("--> [%s] ABOR\n", ftp->url->hostname);

    /* read remaining bytes from connection */
    while(fp && fread(buf, 1, 4096, fp) > 0)
        /* LOOP */ ;

    /* we expect a 426 or 226 reply here... */
    ftp_read_reply();
    if(ftp->fullcode != 426 && ftp->fullcode != 226)
        ftp_trace("Huh!? Expected a 426 or 226 reply\n");

    /* ... and a 226 or 225 reply here, respectively */
    /* FIXME: should skip this reply if prev. reply wasn't 426 or 226 ? */
    ftp_read_reply();
    if(ftp->fullcode != 226 && ftp->fullcode != 225)
        ftp_trace("Huh!? Expected a 226 or 225 reply\n");

    return -1;
}