Android Question FTP upload only works in debug mode

PdeG

Member
Licensed User
Longtime User
When I run the code below in release mode, on a real device, only 1 file is uploaded to the server, the "If Success' is never triggered, but when I run it in debug mode all the files of the 36 files are send to the ftp server, I must be missing something.

I use B4A 10.2 and Net library v1.80

B4X:
Public Sub UploadOrderData(pickerId As String)
    Dim pickerSendPath, pickerId, uploadFolder As String
    Dim filesToSend, filesSent As List
    
    uploadFolder = Starter.ftpFolder
    pickerSendPath = $"/scan_app/${pickerId}/sent/"$
    
    'GET FILES
    filesToSend = File.ListFiles(uploadFolder)
    If filesToSend.Size = 0 Then
        Return
    End If
    
    filesSent.Initialize
    
    If ftp.IsInitialized = False Then
        ftp.Initialize("FTP", Starter.ftpServer, Starter.ftpPort, Starter.ftpUserName, Starter.FtpPassword)
        ftp.PassiveMode = True
   End If
    
    ProgressDialogShow2("Bestanden versturen..", False)
    Sleep(300)
    Log($"FILES : ${filesToSend.Size}"$)
    For i = 0 To filesToSend.Size - 1
        Log(i)
        Log($"FILE NAME : ${filesToSend.Get(i)} - ${pickerSendPath}${filesToSend.Get(i)}"$)
        Dim sf As Object = ftp.UploadFile(uploadFolder, filesToSend.Get(i), False, $"${pickerSendPath}${filesToSend.Get(i)}"$)
        
        Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
        
        If Success Then
            Log($"$Time{DateTime.now}"$)
            filesSent.Add(filesToSend.Get(i))
        Else
            Log(LastException.Message)
        End If
    Next
    
    ftp.Close
    
    ProgressDialogHide
  End Sub
 

PdeG

Member
Licensed User
Longtime User
The problem was server-side, but I wonder why in debug-mode the same code works, anyhow thanks for the reply.

Regards,
Peter

Your code looks correct (though you should learn how to use For Each, much nicer).
You are absolutely right and better readable.

B4X:
For Each fileToSend As String In filesToSend
Log($"FILE NAME : ${fileToSend } - ${pickerSendPath}${fileToSend }"$)
vs
B4X:
For i = 0 To filesToSend.Size - 1
Log($"FILE NAME : ${filesToSend.Get(i)} - ${pickerSendPath}${filesToSend.Get(i)}"$)
 
Upvote 0
Top