void getfile_command(int argc, char **argv) { uint32_t id; char *endptr; char *file; if ( argc != 3 ) { getfile_usage(); return; } id = strtoul(argv[1], &endptr, 10); if ( *endptr != 0 ) { fprintf(stderr, "illegal value %s\n", argv[1]); return; } else if ( ! id ) { fprintf(stderr, "bad file/track id %u\n", id); return; } file = argv[2]; printf("Getting file/track %d to local file %s\n", id, file); if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) { printf("\nError getting file from MTP device.\n"); } printf("\n"); return; }
int MTPDevice::filePull(const std::string &src, const std::string &dst) { const std::string src_basename(smtpfs_basename(src)); const std::string src_dirname(smtpfs_dirname(src)); const TypeDir *dir_parent = dirFetchContent(src_dirname); const TypeFile *file_to_fetch = dir_parent ? dir_parent->file(src_basename) : nullptr; if (!dir_parent) { logerr("Can not fetch '", src, "'.\n"); return -EINVAL; } if (!file_to_fetch) { logerr("No such file '", src, "'.\n"); return -ENOENT; } if (file_to_fetch->size() == 0) { int fd = ::creat(dst.c_str(), S_IRUSR | S_IWUSR); ::close(fd); } else { logmsg("Started fetching '", src, "'.\n"); criticalEnter(); int rval = LIBMTP_Get_File_To_File(m_device, file_to_fetch->id(), dst.c_str(), nullptr, nullptr); criticalLeave(); if (rval != 0) { logerr("Could not fetch file '", src, "'.\n"); LIBMTP_Dump_Errorstack(m_device); LIBMTP_Clear_Errorstack(m_device); return -ENOENT; } } logmsg("File fetched '", src, "'.\n"); return 0; }
void getfile_function(char * from_path,char * to_path) { int id = parse_path (from_path,files,folders); if (id > 0) { printf("Getting %s to %s\n",from_path,to_path); if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) { printf("\nError getting file from MTP device.\n"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } } }
int getfile_command(int argc, char **argv) { uint32_t id; char *endptr; char *file; int ret = 0; // We need file ID and filename if ( argc != 3 ) { getfile_usage(); return 0; } // Sanity check song ID id = strtoul(argv[1], &endptr, 10); if ( *endptr != 0 ) { fprintf(stderr, "illegal value %s\n", argv[1]); return 1; } else if ( ! id ) { fprintf(stderr, "bad file/track id %u\n", id); return 1; } // Filename, e.g. "foo.mp3" file = argv[2]; printf("Getting file/track %d to local file %s\n", id, file); // This function will also work just as well for tracks. if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) { printf("\nError getting file from MTP device.\n"); ret = 1; } // Terminate progress bar. printf("\n"); return ret; }