hBasic Transfer of Files
How to get your *.BAS files from your PC to your target device. |
||||||||||||||||||||||||||||||
Paths
Base Drive (or Base Path)
The base_drive or
BasePath is the
start of scoped storage (see later).
It is usually found at <sdcard>/Android/data/com.rfo.hbasic.
(note: legacy Basic's default base drive used to be
just <sdcard>/)
Base Directory
The base_directory
= base_drive +
rfo-basic
e.g
<sdcard>/Android/data/com.rfo.hbasic/rfo-basic
e.g
/storage/emulated/0/Android/data/com.rfo.hbasic/rfo-basic
with source, data &
databases under
this base.
App Path
The App_Path or app
directory is just the name e.g "rfo-basic" (historically, it
has been mis-named).
This will be different for custom (standalone) apps.
hBasic source and data files have been put in Scoped Storage since v3.00.
This is because Google has been restricting storage
areas aggressively since Android 11. |
||||||||||||||||||||||||||||||
The Problem with
Scoped Storage
Scoped storage is an
area where an individual app has complete access to but
other apps do not.
It is a secure safe area. But this also hinders the developer. It means that it is difficult to transfer your files in and out of hBasic. To get around this, hBasic has a built-in ftp server called hFTP. (ack: Moritz Stückler) Instructions to use it are here. But you don't neccessarly need to use it if you can use one of the other methods below. |
||||||||||||||||||||||||||||||
Ways to
Transfer On one side is the server. The other side is the client. All the file operations must be done at the client end.
Since Android 14, Google enforces that no third party
app can access another app's scoped storage. |
||||||||||||||||||||||||||||||
Method A - Android is
Server Make sure your phone has a wifi connection to your local router and that your PC is also connected to your router. For this method you must start hBasic's built-in FTP server and all file operations are done on the PC client. For the client on the PC, any FTP client can connect. Recommended is FileZilla. This can either be Windows or Linux. The PC client setup is as follows;
Get the host address of hFTP server Run the hFTP server in hBasic. It will display the LAN IP address of that the server uses. e.g 192.168.XXX.YYY Enter this as the host address in your FTP client. Start your PC's FTP client to connect. You should see the listing at the root of the server e.g
files This is the Base Drive which is the start of
hBasic's scoped storage.rfo-basic Navigate into rfo-basic, and you should see the source, data & databases directories. |
||||||||||||||||||||||||||||||
Method B - PC is
Server
** This method
only works for Android 13 or lower **
Make sure your phone has a wifi connection to your
local router and that your PC is also connected to your
router.
The hFTP server is not needed. For this method you must setup a folder-share either on Windows or Linux. All file operations are done on the Android client. For the client on Android, any client that can connect to a SMB share will work. Recommended is Total Commander+LAN plugin. The SMB server setup is as follows;
For Windows PC (folder share)
Explorer> [right=click folder] > Properties
> Sharing > Share > [Share] > Done
(you MUST click the [Share] button) This will show your share pathe.g \\HOSTNAME\Users\userName\shared_dir Write this down. Convert path and slashes to hostname/users/userName/shared_dir (lower case is ok) You need this path to setup TC LAN plugin later. If you need to delete the share at any time,
Computer Management > System Tools> Shared
Folders > Shares > [right-click folder] Stop
Sharing.
For Linux PC (samba share)
Make sure the samba package is
installed.
Copy the sample file from /usr/share/samba/smb.conf
to /etc/samba/smb.conf
and edit it. Add your shared directory to be served; [share_name] comment = myshare path = /home/your_user_name/shared_dir writeable = yes valid users = your_user_name Then reboot. The Android client setup is as follows e.g;
Total Commander LAN(Windows shares) > New server >
Start your Android SMB client to connect. You should
see the listing at the root of the folder e.g shared_dir. On the other pane of Total Commander, navigate to Internal shared storage > (e.g /storage/emulated/0) > Android/data/com.rfo.hbasic/
files This is the Base Drive which is the start of
hBasic's scoped storage.rfo-basic Navigate into rfo-basic, and you should see the source, data & databases directories. |
||||||||||||||||||||||||||||||
Method C - Android
Debug Bridge
I include this method, because sooner or later Method B
will not work for newer versions of Android 14+. A lot of professional developers use this method, but don't let that put you off, you only need to know about a few commands.
The advantage of an ADB connection is
Storage Access (including scoped storage) App installation (streamed apk install) Custom scripts Faster overall work flow speed
In this setup, both client and server are running on
the PC. The server communicates with a daemon on the
target device. Setup ADB
Install ADB on your PC using
this guide found at xda-developers.com. Wired-Connection
To start off,
the xda guide explains how to get a connection
between your PC and device using a USB cable.Do not be put off, as it is not complex. It is just a program that runs on your PC that connects with your phone. Once setup, adb does many more things than transferring files. WiFi-Connection The xda guide also shows you how to get a wifi connection via Developer settings (ADB via WiFi). Not all devices may support this. WiFi-Trick If your device does not support ADB via WiFi, you can use a trick that fixes the connection port to e.g 5555, however this method is per-session, so you may have to do it for every session.
1. Make sure you can connect and operate via a USB
cable.
2. adb tcpip 5555
This fixes the device to start listening for
connections on port 5555; 3. Disconnect the USB cable.4. Get the device IP ( Settings > About Phone > Deailed > Status > IP address ) 5. Connect to the device
adb
connect <device_ip_address>
or This connects to the device
via wifi.adb connect <device_ip_address>:5555 e.g
adb connect 192.168.0.101
or adb connect
192.168.0.101:5555 When your session has finished
adb
disconnect <device_ip_address>
To switch out of wifi and go back to USB mode, adb usb
Useful adb commands
Here are some common commands. You can incorporate them
into your own scripts.
Example : Copy a file into hBasic's source
directory.
adb push aFile.bas
/sdcard/Android/data/com.rfo.hbasic/rfo-basic/source/aFile.bas adb shell chmod 666 /sdcard/Android/data/com.rfo.hbasic/rfo-basic/source/aFile.bas
(obviously this is verbose, so you would be writing
your own scripts to simplify) The second command is neccessary to fix permissions because you may later want to edit the file with hBasic's Editor. ( When files are copied this way, the copier (adb) is not the phone_user and files can end up as read-only. )
SciTE Integration
If you are using the SciTE text editor, you can add a shortcut to call your script for file transfer. In the Language menu, use the 'FreeBasic configuration file. Find the freebasic property file on you installation (usually /usr/share/scite/freebasic.properties). Add these two lines at the bottom of the file;
command.name.1.$(file.patterns.freebasic)=adb PUSH
command.1.$(file.patterns.freebasic)=/path-to-your-script/your-script.sh $(FileNameExt)
This shortcut should turn up as Ctrl-1 in the Tools
menu. -End |
||||||||||||||||||||||||||||||
Method D -
Shizuku
Shizuku is a third-party app which acts as a
permissions broker. It grants permissions for an app, in particular it grants permissions for TotalCommander when using Method B for Android 14+. This means that TotalCommander will be able to access Android/data//com.rfo.hbasic/. The version of TotalCommander that works with Shizuku was announced here. For this to work, you must also install Shizuku on a device with Android 11 or above. Internally, Shizuku uses method C, which means that a number of steps need to be done before usage. To set this up, please refer to the Shizuku Guide. |