+ case PI_CMD_TRANSFERFILE:
+ if (argc < 4) {
+ printf ("Please specify a source and destination filename in addition to the command.\n");
+ printf ("Example: %s --transfer platforms/platform.h snakes.h\n", argv[0]);
+ }
+ if (pi_get_filesize(argv[2], &tmpvalue) == PI_RES_FILENOTFOUND) {
+ printf ("File %s not found on the Pi side.\n", argv[2]);
+ } else {
+ unsigned int filesize = tmpvalue;
+ unsigned char *dest = malloc(filesize);
+
+ if (dest == NULL) {
+ printf ("Failed to allocate memory buffer for file. Aborting file transfer.\n");
+ } else {
+ printf ("Found a %d byte file on the Pi side. Eating it.\n", filesize);
+ if (pi_transfer_file(argv[2], dest) != PI_RES_OK) {
+ printf ("Something went horribly wrong during the file transfer.\n");
+ } else {
+ FILE *out = fopen(argv[3], "wb+");
+ if (out == NULL) {
+ printf ("Failed to open output file %s for writing.\n", argv[3]);
+ } else {
+ fwrite(dest, filesize, 1, out);
+ fclose(out);
+ printf ("%d bytes transferred to file %s.\n", filesize, argv[3]);
+ }
+ }
+ free(dest);
+ }
+ }
+ break;