Al Summers
Member
This is a simple file transfer app. (that will be part of a much bigger beehive inspection application - already written but now growing).
This part copies the database from the logging device (an Android phone Samsung SM-J700F running Android 6.0.1) to a
PC running the latest version of Windows 10.
The client app. (win10) copies the "HiveInspections.db" file from the phone (the server) without a problem.
I would then like to copy any files in two other directories (reports & pictures). But so far all I can get ftp.List("/Android/data/b4a.hives/files/pictures")
to do is list files and directories in "/" and even then it doesn't do this recursively.
The two attached .zip files should be both the client and server parts of this little app. (Please Note: I intend using the file list derived from ftp.List to retrieve
the files from the server/phone - this has not yet been implemented. Also the IP, Port and File path data entry labels on the UI do nothing yet).
Filezilla can access all of the directories I need ie running the phone based server part and accessing from the PC using Filezilla.
The two parts of the app have been based on/lifted from code posted on the B4X forums, without which I wouldn't have made it this far - so thank you all.
So any ideas? What am I missing/doing wrong?
Many Thanks,
Al
This is the first part of the logged output.
'/Android/data/b4a.hives/files/pictures' should contain just one .jpg file
but is actually the listing of all dirs. and files in the top level.
Waiting for debugger to connect...
Program started.
Server Path = /Android/data/b4a.hives/files/pictures
Samsung
Android <-- Dir 1, but nothing below this directory
.mobvista
tbs
OLYMPUS
.KRSDK
.SDKDownloads
Playlists
data <-- Not the 'data' I need.
Download
DCIM
tencent
.here-maps
Pictures
com.android.calendar.subscription.a
Books
360
LD-Log_FREE
rdtmp
Documents
ShareMemo
Media
etc etc
Followed by the top level files;
Contacts.vcf, 3037, 11/03/2015
driveinfo.calibre, 262, 11/08/2015
metadata.calibre, 876, 11/08/2015
qs.pid, 6, 01/09/2016
ota, 398726, 09/14/2020
userconfig.dat, 697, 10/15/2017
B4J Client
B4A Server
This part copies the database from the logging device (an Android phone Samsung SM-J700F running Android 6.0.1) to a
PC running the latest version of Windows 10.
The client app. (win10) copies the "HiveInspections.db" file from the phone (the server) without a problem.
I would then like to copy any files in two other directories (reports & pictures). But so far all I can get ftp.List("/Android/data/b4a.hives/files/pictures")
to do is list files and directories in "/" and even then it doesn't do this recursively.
The two attached .zip files should be both the client and server parts of this little app. (Please Note: I intend using the file list derived from ftp.List to retrieve
the files from the server/phone - this has not yet been implemented. Also the IP, Port and File path data entry labels on the UI do nothing yet).
Filezilla can access all of the directories I need ie running the phone based server part and accessing from the PC using Filezilla.
The two parts of the app have been based on/lifted from code posted on the B4X forums, without which I wouldn't have made it this far - so thank you all.
So any ideas? What am I missing/doing wrong?
Many Thanks,
Al
This is the first part of the logged output.
'/Android/data/b4a.hives/files/pictures' should contain just one .jpg file
but is actually the listing of all dirs. and files in the top level.
Waiting for debugger to connect...
Program started.
Server Path = /Android/data/b4a.hives/files/pictures
Samsung
Android <-- Dir 1, but nothing below this directory
.mobvista
tbs
OLYMPUS
.KRSDK
.SDKDownloads
Playlists
data <-- Not the 'data' I need.
Download
DCIM
tencent
.here-maps
Pictures
com.android.calendar.subscription.a
Books
360
LD-Log_FREE
rdtmp
Documents
ShareMemo
Media
etc etc
Followed by the top level files;
Contacts.vcf, 3037, 11/03/2015
driveinfo.calibre, 262, 11/08/2015
metadata.calibre, 876, 11/08/2015
qs.pid, 6, 01/09/2016
ota, 398726, 09/14/2020
userconfig.dat, 697, 10/15/2017
B4J Client
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Private Label1 As Label
Private ftfClientPath As B4XFloatTextField
Private ftfServerPath As B4XFloatTextField
Private ftfIP As B4XFloatTextField
Private ftfPort As B4XFloatTextField
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
ftfClientPath.Text = "D:\Data\Temp09"
ftfServerPath.Text = "/Android/data/b4a.hives/files/database/HiveInspections.db"
ftfIP.Text = "192.168.1.65"
ftfPort.Text = 51041
End Sub
Sub Button1_Click
DownloadFile("HiveInspections.db")
ListFiles("/Android/data/b4a.hives/files/pictures")
End Sub
Private Sub DownloadFile(filename As String)
Dim ftp As FTP
'ftp.Initialize("ftp","[server IP or url]",21,"[user]","[password]")
ftp.Initialize("ftp","192.168.1.65",51041,"Test","test") '
ftp.PassiveMode=True
ftp.TimeoutMs=60000
Dim sf As Object = ftp.DownloadFile("/Android/data/b4a.hives/files/database/"& filename,False,"D:\Data\Temp09",filename)
Wait For (sf) ftp_DownloadCompleted (ServerPath As String, Success As Boolean)
If Success Then
Label1.Text = filename & " file was downloaded successfully"
Else
Label1.Text = "Error downloading file " & filename
End If
ftp.Close
End Sub
Private Sub ListFiles(path As String)
Dim ftp As FTP
'ftp.Initialize("ftp","[server IP or url]",21,"[user]","[password]")
ftp.Initialize("ftp","192.168.1.65",51041,"Test","test") '
ftp.PassiveMode=True
ftp.TimeoutMs=60000
' Now get pictures and reports
ftp.List(path) '<-- Regardless of 'path' value this just returns two directories below '/'
ftp.Close
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub ftp_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
Log("Server Path = " & ServerPath)
If Success = False Then
Log(LastException)
Else
For i = 0 To Folders.Length - 1
Log(Folders(i).Name)
Next
For i = 0 To Files.Length - 1
Log(Files(i).Name & ", " & Files(i).Size & ", " & DateTime.Date(Files(i).Timestamp))
Next
End If
End Sub
B4A Server
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private rp As RuntimePermissions
End Sub
Sub Globals
Private lblState As Label
Private lblServer As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
Starter.server.Start
Else
lblServer.Text = "No permission!"
End If
End Sub
Sub Activity_Resume
FTPServer_StateChanged
End Sub
Public Sub FTPServer_StateChanged
lblServer.Text = $"Server address: ${Starter.server.ssocket.GetMyWifiIP}
Port: ${Starter.server.Port}"$
lblState.Text = $"Number of clients: ${Starter.server.NumberOfClients}"$
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub