예제 #1
0
void ftpmap_download(ftpmap_t *ftpmap) {
    int fsize = ftpmap_fsize(ftpmap);
    int dsize = 0, rsize = 0;
    FILE *fd, *file;
    char *filename = NULL;
    char *answer = NULL;
    char buffer[MAX_STR];

    filename =  (strrchr(ftpmap->path, '/'))+1;

    if (( file = fopen(filename, "w")) == NULL )
        die(1, "Failed to write %s.", ftpmap->path);

    fd = ftpmap_data_tunnel(ftpmap);
    fprintf(ftpmap->fid, "RETR %s\r\n", ftpmap->path);
    answer = ftpmap_getanswer(ftpmap);

    if ( *answer == 0 )
        return;

    while (( rsize = fread(buffer, 1, sizeof(buffer), fd)) > 0 ) {
        if ( buffer[rsize +1] == '\r' )
            buffer[rsize +1] = '\0';       
        dsize += fwrite(buffer, 1, rsize, file);
        printf(":-: Downloading %s %s/%s ...\r",ftpmap->path,calc_bytes_size(dsize), 
                calc_bytes_size(fsize));
        fflush(stdout);
    }
    printf("\n:-: File saved: %s\n", filename);
    fclose(file);
}
예제 #2
0
파일: client.c 프로젝트: pentestit/ftpmap
void ftpmap_delete(ftpmap_t *ftpmap) {
    char *answer = NULL;

    fprintf(ftpmap->fid, "DELE %s\r\n", ftpmap->deletepath);
    answer = ftpmap_getanswer(ftpmap);
    if ( *answer == 0 )
        return;
    logger_write(ftpmap,":: %s", answer);
}
예제 #3
0
파일: client.c 프로젝트: pentestit/ftpmap
void ftpmap_mdtm(ftpmap_t *ftpmap) {
    char *answer = NULL;

    fprintf(ftpmap->fid, "MDTM %s\r\n", ftpmap->mdtmpath);
    answer = ftpmap_getanswer(ftpmap);
    if ( *answer == 0 )
        return;

    logger_write(ftpmap,":: %s",answer);
}
예제 #4
0
파일: client.c 프로젝트: p2600/ftpmap
void ftpmap_upload(ftpmap_t *ftpmap) {
    FILE *lfp, *fd;
    int fsize = 0;
    int rsize = 0, dsize = 0;
    int buffer[MAX_STR];
    char *filename = "d";
    char *answer = NULL;
   
    if ( strrchr(ftpmap->path, '/'))
        filename = (strrchr(ftpmap->path, '/'))+1;
    else
        filename = ftpmap->path;
    if (( lfp = fopen(ftpmap->path, "rb")) == NULL )
        die(1, "Failed to read \'%s\' ...", ftpmap->path);

    fseek(lfp, 0L, SEEK_END);
    fsize += (int)ftell(lfp);
    fseek(lfp, 0L, SEEK_SET);

    fd = ftpmap_data_tunnel(ftpmap, "w");
    
    fprintf(ftpmap->fid, "TYPE I\r\n");
    answer = ftpmap_getanswer(ftpmap);
    if ( *answer == 0 )
        return;

    fprintf(ftpmap->fid, "STOR %s\r\n", filename);
    answer = ftpmap_getanswer(ftpmap);
    if ( *answer == 0 )
        return;

    logger_write(ftpmap, ":-: %s", answer);
    while (( rsize = fread(buffer, 1, sizeof(buffer), lfp)) > 0 ) {
        if ( buffer[rsize +1 ] == '\r' ) 
            buffer[rsize + 1] = '\0';
        dsize += fwrite(buffer, 1, rsize, fd);
        printf(":-: Uploading %s %s/%s bytes...\r", filename, calc_bytes_size(dsize), 
                calc_bytes_size(fsize));
        fflush(stdout); 
    }
    printf(":-: File \'%s\' Uploaded ...\n", filename);
    fclose(lfp);
}
예제 #5
0
파일: client.c 프로젝트: p2600/ftpmap
long int ftpmap_fsize(ftpmap_t *ftpmap) {
    char *answer = NULL;
    long int size = 0;
    char code[MAX_STR];

    fprintf(ftpmap->fid, "SIZE %s\r\n", ftpmap->path); 
    sscanf( ftpmap_getanswer(ftpmap), "%s %d", code, &size);

    return size;
}
예제 #6
0
파일: client.c 프로젝트: pentestit/ftpmap
void ftpmap_getlist(ftpmap_t *ftpmap) {
    FILE *fid;
    char buffer[MAX_STR];
    char *answer = NULL;

    logger_write(ftpmap,":: Trying to receive LIST..\n\n");
    fid = ftpmap_data_tunnel(ftpmap);
    fprintf(ftpmap->fid, "LIST %s\r\n", ftpmap->listpath);
    answer = ftpmap_getanswer(ftpmap);

    signal(SIGALRM, sigalrm);
    alarm(5);

    while ( (fgets(buffer, sizeof(buffer), fid)) != NULL ) {
        logger_write(ftpmap,"%s", buffer);
    }
    logger_write(ftpmap,":: End of output\n");
}
예제 #7
0
파일: client.c 프로젝트: p2600/ftpmap
void ftpmap_getlist(ftpmap_t *ftpmap) {
    FILE *fid;
    char buffer[MAX_STR];
    char *answer = NULL;
    
    printf(":: Getting LIST..\n\n");
    fid = ftpmap_data_tunnel(ftpmap, "r");
    fprintf(ftpmap->fid, "LIST %s\r\n", ftpmap->path);
    answer = ftpmap_getanswer(ftpmap);

    signal(SIGALRM, sigalrm);
    alarm(5);

    while ( (fgets(buffer, sizeof(buffer), fid)) != NULL ) {
        printf("%s", buffer);
    }
    printf("\n:: End of output\n");
}