예제 #1
0
void show_fun(int fd_client)
{
	printf("+==========================================+\n");
	printf("| Weclome to my ftp!                       |\n");
	printf("+==========================================+\n");
	printf("| Select function:                         |\n");
	printf("| 1.cd + path                              |\n");
	printf("| 2.upload: command: puts + filename       |\n");
	printf("| 3.download:command:gets + filename       |\n");
	printf("+==========================================+\n");
	char send_buf[1024];
	char file_name[20][32];
	char command[64];
	int len,re_len,file_num =0;
	char consle[64] = "";
	memset(consle,0,1024);
	int consle_len;
	recv(fd_client,&consle_len,sizeof(int),0);
	recv(fd_client,&consle,consle_len,0);
	while(printf("%s "),fflush(stdout),memset(send_buf,0,1024),fgets(send_buf,1024,stdin)!=NULL)
	{	
		if( send_buf[0] == '\n')
			continue;
		send_buf[strlen(send_buf)-1] = '\0';
		len = strlen(send_buf);
		send(fd_client,&len,sizeof(len),0);
		send(fd_client,send_buf,strlen(send_buf),0);
		file_num = get_command(send_buf,file_name,command);
		//
		if( 0 == strncmp(command,"cd",3) )
		{
			handle_ccd(fd_client,consle);

		}else if( 0 == strncmp(command,"ls",3) )
		{
			;

		}else if( 0 == strncmp(command,"gets",5) )
		{
			handle_download(fd_client,file_num,file_name);

		}else if( 0 == strncmp(command,"puts",5) )
		{
			handle_upload(fd_client,file_num,file_name);

		}else if( 0 == strncmp(command,"rm",3) )
		{
			;
		}else if( 0 == strncmp(command,"bye",4) )
		{
			break;
		}
		else
		{
			printf("error command\n");
		}

	}	
}
예제 #2
0
static int download(csiebox_client *client) 
{
	int finish = 0;
	while(!finish) {
		finish = handle_download(client);
	}
	return 1;
}
예제 #3
0
void driver_command_data_received(driver_command_t *driver, uint8_t *data, size_t length)
{
    command_packet_t *in  = NULL;
    command_packet_t *out = NULL;

    buffer_add_bytes(driver->stream, data, length);

    while((in = command_packet_read(driver->stream)))
    {
        /* TUNNEL_DATA commands are too noisy to print. */
        if(in->command_id != TUNNEL_DATA)
        {
            printf("Got a command: ");
            command_packet_print(in);
        }

        switch(in->command_id)
        {
        case COMMAND_PING:
            out = handle_ping(driver, in);
            break;

        case COMMAND_SHELL:
            out = handle_shell(driver, in);
            break;

        case COMMAND_EXEC:
            out = handle_exec(driver, in);
            break;

        case COMMAND_DOWNLOAD:
            out = handle_download(driver, in);
            break;

        case COMMAND_UPLOAD:
            out = handle_upload(driver, in);
            break;

        case COMMAND_SHUTDOWN:
            out = handle_shutdown(driver, in);
            break;

        case COMMAND_DELAY:
            out = handle_delay(driver, in);
            break;

        case TUNNEL_CONNECT:
            out = handle_tunnel_connect(driver, in);
            break;

        case TUNNEL_DATA:
            out = handle_tunnel_data(driver, in);
            break;

        case TUNNEL_CLOSE:
            out = handle_tunnel_close(driver, in);
            break;

        case COMMAND_ERROR:
            out = handle_error(driver, in);
            break;

        default:
            LOG_ERROR("Got a command packet that we don't know how to handle!\n");
            out = command_packet_create_error_response(in->request_id, 0xFFFF, "Not implemented yet!");
        }

        /* Respond if and only if an outgoing packet was created. */
        if(out)
        {
            uint8_t *data;
            size_t   length;

            if(out->command_id != TUNNEL_DATA)
            {
                printf("Response: ");
                command_packet_print(out);
            }

            data = command_packet_to_bytes(out, &length);
            buffer_add_bytes(driver->outgoing_data, data, length);
            safe_free(data);
            command_packet_destroy(out);
        }
        command_packet_destroy(in);
    }
}