3 * Example program to retrieve a file off the device.
5 * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
6 * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
27 #include "pathutils.h"
30 extern LIBMTP_folder_t *folders;
31 extern LIBMTP_file_t *files;
32 extern LIBMTP_mtpdevice_t *device;
34 void getfile_usage (void)
36 fprintf(stderr, "getfile <fileid/trackid> <filename>\n");
40 getfile_function(char * from_path,char * to_path)
42 int id = parse_path (from_path,files,folders);
44 printf("Getting %s to %s\n",from_path,to_path);
45 if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) {
46 printf("\nError getting file from MTP device.\n");
47 LIBMTP_Dump_Errorstack(device);
48 LIBMTP_Clear_Errorstack(device);
56 int getfile_command(int argc, char **argv)
63 // We need file ID and filename
69 // Sanity check song ID
70 id = strtoul(argv[1], &endptr, 10);
72 fprintf(stderr, "illegal value %s\n", argv[1]);
75 fprintf(stderr, "bad file/track id %u\n", id);
79 // Filename, e.g. "foo.mp3"
81 printf("Getting file/track %d to local file %s\n", id, file);
83 // This function will also work just as well for tracks.
84 if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) {
85 printf("\nError getting file from MTP device.\n");
88 // Terminate progress bar.