summaryrefslogtreecommitdiffstats
path: root/src/tests/ftptest.c
blob: 6b0002fbecb19e952daa050a010f97a59fb70969 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdint.h>
#include <string.h>
#include <byteswap.h>
#include <console.h>
#include <vsprintf.h>
#include <gpxe/async.h>
#include <gpxe/ftp.h>

static void test_ftp_callback ( char *data, size_t len ) {
	unsigned int i;
	char c;

	for ( i = 0 ; i < len ; i++ ) {
		c = data[i];
		if ( c == '\r' ) {
			/* Print nothing */
		} else if ( ( c == '\n' ) || ( c >= 32 ) || ( c <= 126 ) ) {
			putchar ( c );
		} else {
			putchar ( '.' );
		}
	}
}

void test_ftp ( struct sockaddr_tcpip *server, const char *filename ) {
	struct ftp_request ftp;
	int rc;

	printf ( "FTP fetching %s\n", filename );
	
	memset ( &ftp, 0, sizeof ( ftp ) );
	memcpy ( &ftp.tcp.peer, server, sizeof ( ftp.tcp.peer ) );
	ftp.filename = filename;
	ftp.callback = test_ftp_callback;

	rc = async_wait ( ftp_get ( &ftp ) );
	if ( rc ) {
		printf ( "FTP fetch failed\n" );
	}
}