Android Question FTP UploadProgress does not fire for every file

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone, i'm trying to use FTP to upload multiple files to the server.
I do it one by one, i want to show a progress bar, so i did like so:


B4X:
'This function uploads the files (stored in the list) to the server base'
Public Sub CaricaFoto
    Log(filenamelist)
   
    currentTotalFiles = filenamelist.Size
    For Each filename In filenamelist
        currentFileSize = File.Size(File.DirInternal & $"/${Starter.FileManager1.NomeCartella}"$, filename)
       
        Dim sf As Object = FTP2.UploadFile(File.DirInternal & $"/${Starter.FileManager1.NomeCartella}"$, filename, False, $"${path}/${filename}"$)
        Wait For (sf) ftp2_UploadCompleted (ServerPath As String, Success As Boolean)
        If Success Then
            LogColor("File Caricato", Colors.Green)
            currentDoneFiles = currentDoneFiles + 1
            'File.Delete(File.DirInternal & $"/${Starter.FileManager1.NomeCartella}"$, filename)
           
            AggiornaProgress(Array As Object (0, currentDoneFiles, currentTotalFiles))
           
            If currentDoneFiles == currentTotalFiles Then 'fine trasferimento
                currentTotalFiles = 0
                currentDoneFiles = 0
                currentFileSize = 0
               
                Log("TRASFERIMENTO COMPLETATO")
                FTP2.Close
            End If
           
            Sleep(0)
        End If
    Next
End Sub

Private Sub ftp2_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    If (TotalUploaded/currentFileSize)*100 > lastProgValue + 5 Then 'if incremented more than 5, i print
        lastProgValue = (TotalUploaded/currentFileSize)*100
        Log($"Filesize: ${currentFileSize}, Progress: ${lastProgValue}"$)
        'AggiornaProgress(Array As Object (lastProgValue, currentDoneFiles, currentTotalFiles))

    End If
End Sub

'This function update the UI'
Public Sub AggiornaProgress(Data() As Object)
    'crcProgress.Value = Data(0) 'the value'
    'lblCountingFile.text = $"${Data(1)}/${Data(2)}"$ 'uploadedsize/totalsize'
    Sleep(10)
End Sub

The problem is that, the _UploadProress sub fires only for the FIRST file D:
I tried with three.
Here you are the logs

ftp1.PNG

See? only for the first file, the logs i put in the _UploadProgress sub are printed, between file 1 and 2, and 2 and 3, no logs, so the sub is not fired

Have you some ideas? D:
 

Mike1970

Well-Known Member
Licensed User
Longtime User
Ok found the problem ahhaha, while editing this post I noticed a clue:

I did not reset the variabile "lastProgValue" to 0 every uploade completed 😅 😅 😅
 
Upvote 0
Top