Android Question FTP - get uploaded file name for deletion

Bobi

Member
Licensed User
Longtime User
I want to upload multiple file from a specific location and, if upload finished with success, I want to delete those files. The problem is when UploadCompleted raise: I do not know the file name. Is there any elegant solution instead extract filename from "ServerPath As String"?

Thanks!

B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    Dim FTPFoto As FTP
End Sub

Sub Service_Create
    Try
        FTPFoto.Initialize("FTPFoto", "ip", "port", "usr", "pass")     
    Catch
        Log("err at FTPFoto.Initialize() " & LastException)
    End Try
End Sub

Sub Service_Start (StartingIntent As Intent)
    ScanForFoto
    StartServiceAt("srvSendFoto", DateTime.Now + 10 * DateTime.TicksPerMinute,True)
End Sub

Sub Service_Destroy
   
End Sub
Sub ScanForFoto
    GetFoto
End Sub

Private Sub GetFoto
    Dim dir As String = File.DirRootExternal
    Try
        For Each f As String In File.ListFiles(dir)
        If File.IsDirectory(dir, f)=False Then
            UploadFoto(dir, f)
            DoEvents
        End If
    Next
    Catch
        Log("err in GetFoto: " & LastException)
    End Try
End Sub

Private Sub UploadFoto (director As String, fisier As String)
    Try
        FTPFoto.UploadFile(director, fisier, False, "/ci/" & fisier)    
    Catch
        Log(LastException)
    End Try
End Sub

Sub FTPFoto_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim upload As String
    upload = Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then upload = upload & " out of " & Round(Total / 1000) & "KB"
    LogColor(upload, Colors.LightGray)
End Sub

Sub FTPFoto_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success = False Then
        Log("err at upload - " & ServerPath)
    End If
    If Success = True Then
        Log("Upload with succes - " & ServerPath)
        File.Delete(File.DirRootExternal, "<What to put here>?") ' <<<<<<<<<<============= here is my problem
    End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top