Page 1 of 1

Script: Send files to Android device over USB

Posted: 20 Jun 2013 18:05
by 40k
Hi all,

This script allows you to select a folder on your computer and send it, and all the files in subfolders, to a location on your Android device.
It uses Android Debugging Bridge so you will need to install that.

https://developer.android.com/sdk/index.html

Make sure to registered adb,exe in your PATH variable or code the absolute location in the script yourself. If this project takes off I will probably expand it with my regular easy to configure interface.

Also, You can only copy to a location on your Android device that already exists. Meaning, You can not copy to /sdcard/myfolder/folder1/ until you have created that folder first on your tablet/phone. It's an easy fix, but like I said below, I'm too lazy to do it right now.

How it works:

1. Select the folder you want to transfer in Xyplorer
2. Input the path to which you want to transfer the folder in the dialogue (Default is /sdcard/)
3. adb transfers your files.

NOTE: You need to enable ADB debugging under developer options in your Android device's Settings.
http://www.androidcentral.com/how-enabl ... android-42

No fancy post this time. It's 25 degrees here in Germany with 85% humidity. That is all :)

Here is the code:

Code: Select all

"_Initialize"
 {
 // Configuration .ini file
 global $g_ConfigurationFile;
 $g_ConfigurationFile = "<xyscripts>\AndroidTransfer.ini";
 
 // Execution and buffer files
 global $g_ExecutionFile;
 $g_ExecutionFile = "<xyscripts>\AndroidTransfer.bat";
 
 // Configuration keys
 global $g_ScriptVersion;
 $g_ScriptVersion = '0.1';

 if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
 
  // Load keys
  
 } else {
  msg <<<#
Script is not configured.
The configuration wizard will assist you.
#;
 
 sub "_Configure";
 } 
 }
 
"_Configure"
 {
 global $g_ConfigurationFile;
 global $g_ScriptVersion;
 
 msg <<<#
This wizard configures the script for first use. To edit the configuration file click "Edit Configuration" after launching the script. If the configuration file is not found or you upgrade to a new version of this script the wizard will appear automatically.

The configuration file is located at:

$g_ConfigurationFile
#;

 // Delete old configuration file
 delete (0, 0, "$g_ConfigurationFile");

 // Define parameters
 
 // Write configuration to disk
 $Configuration = <<<#
[Configuration]
ScriptVersion=$g_ScriptVersion
#;

 writefile ("$g_ConfigurationFile", "$Configuration", o, t);
 
 msg <<<#
Configuration completed.
#;
 }

"Send Folder Content"
 {
 global $g_SendFolder;
 $g_SendFolder = get ('SelectedItemsPathNames', '|', 'a');
 
 global $g_LocalRoot;
 $g_LocalRoot = getpathcomponent ("$g_SendFolder", 'path');
 
 if ($g_LocalRoot == getpathcomponent ("$g_LocalRoot", 'drive'){
 $g_LocalRoot = getpathcomponent ("$g_LocalRoot", 'drive').':';
 }
 
 global $g_DeviceRoot;
 $g_DeviceRoot = input ( , 'Define Android device folder to send to', '/sdcard/', 's', , , ); 
 
 // List with all absolute paths
 global $g_SendFolderSubTree;
 sub "_GetSendFolderSubTree";
 
 sub "_MkdirSendFolderSubTree";
 
 sub "_GetSendFiles"; 

 sub "_PushSendFolderFiles";
 }

"_GetSendFolderSubTree"
 {
 global $g_SendFolder;
 
 global $g_SendFolderSubTree;
 $g_SendFolderSubTree = folderreport ('dirs', 'r', "$g_SendFolder", 'r', , '|');
 $g_SendFolderSubTree = $g_SendFolderSubTree.'|'.$g_SendFolder;
 $g_SendFolderSubTree = formatlist ("$g_SendFolderSubTree", 'e', '|', );
 }

"_MkdirSendFolderSubTree"
 {
 global $g_SendFolderSubTree;
 
 global $g_ExecutionFile;
 delete ('0', '0', "$g_ExecutionFile");

 global $g_LocalRoot;
 global $g_DeviceRoot;
 
 foreach ($Folder, $g_SendFolderSubTree, '|'){
  $Folder = replace ("$Folder", "$g_LocalRoot", "$g_DeviceRoot", '0', , );
  $Folder = replacelist ("$Folder", '/,\,\\,/\,\/', '/', ',' '0');
  $Folder = regexreplace ("$Folder", '//', '/', '0');
  
  writefile ("$g_ExecutionFile",'adb shell mkdir -p "'.$Folder.'"'."<crlf>", 'a', 't');
 }
 
 run ("$g_ExecutionFile", , '1', '1');
 
 }
 
"_GetSendFiles"
 {
 global $g_SendFolder;
 global $g_SendFiles;

 $g_SendFiles = folderreport ('files', 'r', "$g_SendFolder", 'r', , '|');
 }

"_PushSendFolderFiles"
 {
 global $g_SendFiles;

 global $g_ExecutionFile;
 delete ('0', '0', "$g_ExecutionFile");

 global $g_LocalRoot;
 global $g_DeviceRoot;

 foreach ($File, $g_SendFiles, '|'){
  
  writefile ("$g_ExecutionFile",'adb push "'.$File.'"'." ", 'a', 't');
  
  $File = replace ("$File", "$g_LocalRoot", "$g_DeviceRoot", '0', , );
  $File = replacelist ("$File", '/,\,\\,/\,\/', '/', ',' '0');
  $File = regexreplace ("$File", '//', '/', '0');
  
  writefile ("$g_ExecutionFile",'"'.$File.'"'."<crlf>", 'a', 't');
 }
 
 run ("$g_ExecutionFile", , '1', '1');
 }
 
 
 
 
 
 
 
 
 


Re: Script: Send files to Android device over USB

Posted: 20 Jun 2013 19:08
by admin
Why do you unnecessarily quote variables ("$g_ConfigurationFile")? Is it the heat or the humidity? :P

Re: Script: Send files to Android device over USB

Posted: 20 Jun 2013 20:15
by serendipity
Thanks for this script. I will test it out. The only time I use WE is to view files on my android device and this will help somewhat.
Maybe one day XY will support this.

Re: Script: Send files to Android device over USB

Posted: 24 Jun 2013 14:30
by 40k
admin wrote:Why do you unnecessarily quote variables ("$g_ConfigurationFile")? Is it the heat or the humidity? :P
I can't figure out what coding convention I want to use for Xy so I sort of make my own. Not that I really stick to it though, ahem... :whistle:

Re: Script: Send files to Android device over USB

Posted: 04 Jul 2013 14:32
by 40k
I'm working on this one at the moment. The next version should consist of just one script that sends any selected items, files and / or folder to your android device.

Re: Script: Send files to Android device over USB

Posted: 04 Jul 2013 18:53
by j_c_hallgren
Just wondering...what advantages does this have over http://www.airdroid.com/ which I and others use all the time for this type function? I presume you're aware of AirDroid? If not, why not?

Re: Script: Send files to Android device over USB

Posted: 04 Jul 2013 19:28
by 40k
j_c_hallgren wrote:Just wondering...what advantages does this have over http://www.airdroid.com/ which I and others use all the time for this type function? I presume you're aware of AirDroid? If not, why not?
This works when you need it to work. Air droid needs a WiFi connection.
Aside from that, you should not need to install 3rd party software to transfer your files. The security implications alone...

I was not aware of air droid, but again, things like file transfer are just too important to be dependent on often sketchy wireless connections in my book.