Exemple #1
0
/* reads reply
 * returns 0 on success or -1 on error
 */
int ftp_read_reply(void)
{
    char tmp[5]="xxx ";
    int r;

    ftp_set_signal(SIGALRM, reply_ALRM_handler);
    if(ftp->reply_timeout)
        alarm(ftp->reply_timeout);

    sock_clearerr_in(ftp->ctrl);
    r = ftp_gets();
    if(!sock_connected(ftp->ctrl)) {
        alarm(0);
        ftp_set_signal(SIGALRM, SIG_DFL);
        ftp_trace("sock is not connected\n");
        return -1;
    }

    if(r == -1) {
        alarm(0);
        ftp_set_signal(SIGALRM, SIG_DFL);
        ftp_trace("ftp_gets returned -1\n");
        return -1;
    }

    ftp_print_reply();

    if(ftp->reply[3] == '-') {  /* multiline response */
        strncpy(tmp, ftp->reply, 3);
        do {
            if(ftp_gets() == -1)
                break;
            ftp_print_reply();
        } while(strncmp(tmp, ftp->reply, 4) != 0);
    }
    ftp->tmp_verbosity = vbUnset;
    alarm(0);
    ftp_set_signal(SIGALRM, SIG_DFL);
    return r;
}
Exemple #2
0
directory *
read_dir(FILE *f)
{
    directory *dir;
    direntry entry;
    int n, pf, ret;
    char *line;
    time_t oldt, newt;

    dir = dir_new();
    n = 0;

    pf = 0;
    oldt = 0;

    init_parse_time();

    while ((line=ftp_gets(f)) != NULL) {
	while ((ret=pfunc[pf](&entry, line)) == -1) {
	    pf++;
	    if (pf >= npfunc) {
		pf = 0;
		ret = 1;
		break;
	    }
	}
	if (ret == 0) {
	    dir_add(dir, &entry);
	    n++;
	}
	free(line);

	if ((newt=time(NULL)) != oldt) {
	    disp_status(DISP_STATUS, "listed %d", n);
	    oldt = newt;
	}
    }

#if 0
    if (n == 0) {
	dir->line = (direntry *)malloc(sizeof(direntry));
	dir->line->line = strdup("");
	dir->line->type = 'x';
	dir->line->name = strdup("");
	dir->line->link = NULL;
	n = 1;
    }
#endif

    return dir;
}