fork download
  1. <?php
  2.  
  3. /**
  4.  * Class adbCopyFiles
  5.  *
  6.  * Copies files from a specified folder on the Android device (over USB, using adb)
  7.  * to the specified folder on the PC.
  8.  *
  9.  * Usage:
  10.  * > php acf.php <from> <to>
  11.  * Where:
  12.  * <from> - Android folder path for example: /sdcard/DCIM/100ANDRO/ (with trailing slash)
  13.  * <to> - PC folder path, for example: ./100ANDRO/ (with trailing slash)
  14.  *
  15.  * Sample output:
  16.  
  17.  * Z:\web\adbCopyFolder>php acf.php
  18. List of devices attached
  19. CB5A1PTCB4 device
  20.  
  21. /sdcard/DCIM/100ANDRO/DSC_0001.jpg Exists
  22. /sdcard/DCIM/100ANDRO/DSC_0002.jpg Exists
  23. /sdcard/DCIM/100ANDRO/DSC_0004.jpg Exists
  24. /sdcard/DCIM/100ANDRO/DSC_0005.jpg Exists
  25. /sdcard/DCIM/100ANDRO/DSC_0006.jpg Exists
  26. /sdcard/DCIM/100ANDRO/DSC_0007.jpg Exists
  27. /sdcard/DCIM/100ANDRO/DSC_0081.jpg Missing
  28. 2203 KB/s (1963546 bytes in 0.870s)
  29. /sdcard/DCIM/100ANDRO/DSC_0082.jpg Missing
  30. 2319 KB/s (2215840 bytes in 0.933s)
  31. /sdcard/DCIM/100ANDRO/DSC_0083.jpg Missing
  32. 2466 KB/s (1788425 bytes in 0.708s)
  33. /sdcard/DCIM/100ANDRO/DSC_0084.jpg Missing
  34. 2621 KB/s (1312938 bytes in 0.489s)
  35.  */
  36.  
  37. class adbCopyFiles {
  38.  
  39. var $adbPath = 'c:\\android\\android-sdk-windows\\platform-tools\\';
  40. var $from = '/sdcard/DCIM/100ANDRO/';
  41. var $to = './100ANDRO/';
  42.  
  43. function __construct() {
  44. $this->call('adb devices');
  45. if ($_SERVER['argc'] == 3) {
  46. $this->from = $_SERVER['argv'][1];
  47. $this->to = $_SERVER['argv'][2];
  48. }
  49. }
  50.  
  51. function call($cmd) {
  52. passthru($this->adbPath.$cmd);
  53. }
  54.  
  55. function grab($cmd) {
  56. exec($cmd, $output);
  57. return $output;
  58. }
  59.  
  60. function noSlash($str) {
  61. $len = strlen($str);
  62. $lastChar = $str{$len-1};
  63. if (in_array($lastChar, array('/', '\\'))) {
  64. return substr($str, 0, -1);
  65. } else {
  66. return $str;
  67. }
  68. }
  69.  
  70. function render() {
  71. $files = $this->grab($this->adbPath.'adb shell ls -R '.$this->from);
  72. array_shift($files); // empty line
  73. array_shift($files); // /sdcard/DCIM/100ANDRO:
  74. foreach ($files as $file) {
  75. $status = file_exists($this->to.$file) ? 'Exists' : 'Missing';
  76. echo $this->from.$file, "\t", $status, "\n";
  77. if ($status == 'Missing') {
  78. $cmd = 'adb pull '.$this->from.$file.' '.$this->noSlash($this->to);
  79. //echo $this->adbPath.$cmd, "\n";
  80. $this->call($cmd);
  81. }
  82. }
  83. }
  84.  
  85. }
  86.  
  87. $acf = new adbCopyFiles();
  88. $acf->render();
  89.  
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
sh: c:androidandroid-sdk-windowsplatform-toolsadb: not found
sh: c:androidandroid-sdk-windowsplatform-toolsadb: not found