Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

sendfile.c
Tuesday, November 20th, 2007 at 7:37:27pm UTC 

  1. /**
  2. * \file sendfile.c
  3. * Example program to send an arbitrary file to a device.
  4. *
  5. * Copyright (C) 2005-2007 Linus Walleij <[email protected]>
  6. * Copyright (C) 2006 Chris A. Debenham <[email protected]>
  7. *
  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.
  12. *
  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.
  17. *
  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.
  22. */
  23. #define _LARGEFILE_SOURCE
  24. #define _LARGEFILE64_SOURCE
  25.  
  26. #include <string.h>
  27. #include <libgen.h>
  28. #include <sys/stat.h>
  29. #include <sys/types.h>
  30. #include <fcntl.h>
  31. #include "common.h"
  32. #include "libmtp.h"
  33. #include "pathutils.h"
  34.  
  35. extern LIBMTP_folder_t *folders;
  36. extern LIBMTP_file_t *files;
  37. extern LIBMTP_mtpdevice_t *device;
  38.  
  39. int sendfile_function(char *);
  40. void sendfile_command(int, char **);
  41. void sendfile_usage(void);
  42.  
  43. void sendfile_usage(void)
  44. {
  45.   fprintf(stderr, "usage: upgrade <local filename>\n");
  46. }
  47.  
  48. int sendfile_function(char * from_path)
  49. {
  50.   printf("Sending %s\n",from_path);
  51.   char *filename;
  52.   uint64_t filesize;
  53. #ifdef __USE_LARGEFILE64
  54.   struct stat64 sb;
  55. #else
  56.   struct stat sb;
  57. #endif
  58.   LIBMTP_file_t *genfile;
  59.   int ret;
  60.   uint32_t parent_id = 0;
  61.  
  62. #ifdef __USE_LARGEFILE64
  63.   if ( stat64(from_path, &sb) == -1 ) {
  64. #else
  65.   if ( stat(from_path, &sb) == -1 ) {
  66. #endif
  67.     fprintf(stderr, "%s: ", from_path);
  68.     perror("stat");
  69.     exit(1);
  70.   }
  71.  
  72. #ifdef __USE_LARGEFILE64
  73.   filesize = sb.st_size;
  74. #else
  75.   filesize = (uint64_t) sb.st_size;
  76. #endif
  77.   filename = basename(from_path);
  78.   parent_id = 0x10001;
  79.  
  80.   genfile = LIBMTP_new_file_t();
  81.   genfile->filesize = filesize;
  82.   genfile->filename = "nk.bin";
  83.   genfile->filetype = LIBMTP_FILETYPE_FIRMWARE;
  84.  
  85.   printf("Sending file...\n");
  86.   ret = LIBMTP_Send_File_From_File(device, from_path, genfile, progress, NULL, parent_id);
  87.   printf("\n");
  88.   if (ret != 0) {
  89.     printf("Error sending file.\n");
  90.     LIBMTP_Dump_Errorstack(device);
  91.     LIBMTP_Clear_Errorstack(device);
  92.   } else {
  93.     printf("New file ID: %d\n", genfile->item_id);
  94.   }
  95.  
  96.   LIBMTP_destroy_file_t(genfile);
  97.  
  98.   return 0;
  99. }
  100.  
  101. void sendfile_command (int argc, char **argv) {
  102.   if (argc < 2) {
  103.     sendfile_usage();
  104.     return;
  105.   }
  106.   sendfile_function(argv[1]);
  107. }

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right