Rfo-Basic > hBasic >Transfer

hBasic
Transfer of Files
How to get your *.BAS files from your PC to your target device.

Paths

The problem with Scoped Storage

Ways to Transfer

Method A PC Client
Method B Android Client
Method C ADB


Android as server
PC as server
ADB ( client, server & daemon)


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
or
e.g /storage/emulated/0/Android/data/com.rfo.hbasic/rfo-basic

with source, data & databases under this base.

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 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.
Instructions to use it are here.
But you don't neccessarly need to use it. There are some file-managers which are able to access hBasic's scoped storage.

Below are some methods to get files in and out of scoped storage.

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.

Choice
Server
Client
User Operations
Remarks
A) hFTP
Device is server
hFTP server inside hBasic on device
FTP (filezilla) client on PC
On PC client
hBasic ftp server





B) SMB
PC is server
Windows shared folder (i.e SMB)
or
Linux (SAMBA)
Total Commander client on device
+ LAN plugin.
On Android client
** Does not work for Android 14+
C) ADB PC+Device daemon
PC
On PC client
Other operations also available

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;

default cmd port
2345
  user Name

hbasic
password
hbasic
mode
passive
type
unix
auth
plain text
host address
(see below)

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
rfo-basic
This is the Base Drive which is the start of hBasic's scoped storage.
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 path
e.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 >

Connection Name
 
anyName
Server name/directory
hostname/users/userName/shared_dir
or
hostname/share_name
User name
(same as PC username)
Password:
(same as PC password) (CANNOT BE EMPTY)
server type

SMB2 or SMB3
other settings

all OFF
OK



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
rfo-basic
This is the Base Drive which is the start of hBasic's scoped storage.
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.
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.

Wired-Connection
To start off, the xda guide explains how to get a connection between your PC and device using a USB cable.

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
adb connect <device_ip_address>:5555
    This connects to the device via wifi.
  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.

adb devices

show conected devices
adb start-server  
start server
adb kill-server
kill server
adb install <package>
install an apk
adb push aFile.bas /sdcard/Android/data/com.rfo.hbasic/rfo-basic/source/aFile.bas
copy a file from PC to device
adb shell chmod 666 <file-path>

make a file writeable



adb push myDir/* /sdcard/Android/data/com.rfo.hbasic/rfo-basic/source/data/
copy multiple files from myDir to the data directory.

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. )

-End



Leading Cloud Surveillance, Recording and Storage service; IP camera live viewing

Leading Enterprise Cloud IT Service; cloud file server, FTP Hosting, Online Storage, Backup and Sharing

Powered by FirstCloudIT.com, a division of DriveHQ, the leading Cloud IT and Cloud Surveillance Service provider since 2003.