I am downloading 7 files that must begin with a given string from a server to a real device using FTP. The total size of the files combined is a little more than 1 MB. The files download properly, but the progress bar seem to hit 100% almost instantly which appears to be too fast. The toastmessage lags too far behind. Below is the code I use for the download and the progressbar calculation:
Thank you for any ambiguity you see in my code.
B4X:
Dim MyFile(100) As String 'names of files on server
Dim i, n as Int
Dim DBFilePath as string 'Device file path
Dim pb As ProgressBar
Dim CurrentFileSize As Int
Dim TargetedFile As String
Dim GrandTotalDownloaded, TotalDownload As Long
'DOWNLOAD BUTTON CLICK
Sub btnDownload_Click
For i = 0 To n - 1 'n is the total number of files in folder returned from FTP_ListCompleted
If MyFile(i).StartsWith("Base_") Then
'Below Export is the alias of the server folder containing the files
FTP.DownloadFile("Export/" & MyFile(i) , False, DBFilePath, MyFile(i))
TargetedFile=MyFile(i)
CurrentFileSize = File.Size(DBFilePath, TargetedFile)
GrandTotalDownloaded=GrandTotalDownloaded + CurrentFileSize
ToastMessageShow("File downloaded: " & MyFile(i),False)
End If
Next
End Sub
'DOWNLOAD PROGRESS
Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
Dim s As String
s = "Downloaded " & Round(TotalDownloaded / 1024) & " KB"
If Total > 0 Then s = s & " out of " & Round(Total / 1024) & " KB"
Log(s)
TotalDownload=TotalDownload + TotalDownloaded
pb.Progress = 100 * TotalDownload / GrandTotalDownloaded
End Sub
'DOWNLOAD COMPLETED
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ", Success=" & Success)
If Success = False Then
Log(LastException.Message)
Msgbox("DOWNLOAD OF BASE FILES FAILED","DOWNLOAD FAILED")
Return
End If
'Msgbox("TOTAL DOWNLOADED: " & Round(GrandTotalDownloaded/1024) & " KB.","")
End Sub