ftptest.c 855B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <byteswap.h>
  4. #include <console.h>
  5. #include <vsprintf.h>
  6. #include <gpxe/async.h>
  7. #include <gpxe/ftp.h>
  8. static void test_ftp_callback ( char *data, size_t len ) {
  9. unsigned int i;
  10. char c;
  11. for ( i = 0 ; i < len ; i++ ) {
  12. c = data[i];
  13. if ( c == '\r' ) {
  14. /* Print nothing */
  15. } else if ( ( c == '\n' ) || ( c >= 32 ) || ( c <= 126 ) ) {
  16. putchar ( c );
  17. } else {
  18. putchar ( '.' );
  19. }
  20. }
  21. }
  22. void test_ftp ( struct sockaddr_tcpip *server, const char *filename ) {
  23. struct ftp_request ftp;
  24. int rc;
  25. printf ( "FTP fetching %s\n", filename );
  26. memset ( &ftp, 0, sizeof ( ftp ) );
  27. memcpy ( &ftp.tcp.peer, server, sizeof ( ftp.tcp.peer ) );
  28. ftp.filename = filename;
  29. ftp.callback = test_ftp_callback;
  30. rc = async_wait ( ftp_get ( &ftp ) );
  31. if ( rc ) {
  32. printf ( "FTP fetch failed\n" );
  33. }
  34. }