00001
00023 #include "common.h"
00024 #include "pathutils.h"
00025
00026 void getfile_function(char *,char *);
00027 void getfile_command(int, char **);
00028 void getfile_usage(void);
00029
00030 extern LIBMTP_folder_t *folders;
00031 extern LIBMTP_file_t *files;
00032 extern LIBMTP_mtpdevice_t *device;
00033
00034 void getfile_usage (void)
00035 {
00036 fprintf(stderr, "getfile <fileid/trackid> <filename>\n");
00037 }
00038
00039 void
00040 getfile_function(char * from_path,char * to_path)
00041 {
00042 int id = parse_path (from_path,files,folders);
00043 if (id > 0) {
00044 printf("Getting %s to %s\n",from_path,to_path);
00045 if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) {
00046 printf("\nError getting file from MTP device.\n");
00047 LIBMTP_Dump_Errorstack(device);
00048 LIBMTP_Clear_Errorstack(device);
00049 }
00050 }
00051 }
00052
00053
00054 void getfile_command(int argc, char **argv)
00055 {
00056 u_int32_t id;
00057 char *endptr;
00058 char *file;
00059
00060
00061 if ( argc != 3 ) {
00062 getfile_usage();
00063 return;
00064 }
00065
00066
00067 id = strtoul(argv[1], &endptr, 10);
00068 if ( *endptr != 0 ) {
00069 fprintf(stderr, "illegal value %s\n", argv[1]);
00070 return;
00071 } else if ( ! id ) {
00072 fprintf(stderr, "bad file/track id %u\n", id);
00073 return;
00074 }
00075
00076
00077 file = argv[2];
00078 printf("Getting file/track %d to local file %s\n", id, file);
00079
00080
00081 if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) {
00082 printf("\nError getting file from MTP device.\n");
00083 }
00084
00085 printf("\n");
00086
00087 return;
00088 }
00089