Android Question all FTP download files are completed.

hub73

Active Member
Licensed User
Longtime User
I download some files on my usb card from FTP. This is an folder and sub folders (recursive). All works fine. But now I just want display 'all finished' into my Label20a when all the FTP2_DownloadCompleted are completed...

any idea ?

Many thanks

Here my code :

B4X:
Sub Recuperer_dossier_complet_nas ()
   
    FTP2.Initialize ("FTP2", EditText3a.Text, 21, EditText4a.Text, EditText5a.Text)
   
    If FTP2.IsInitialized = True Then
        Label20a.Text = "Connexion FTP2 au NAS établie."
    Else
        Label20a.Text = "Connexion FTP2 au NAS non établie !"
    End If
   
    FTP2.List(EditText11a.Text)
   
end  sub

Sub Copier_ce_fichier (CheminFichierComplet As String)

    Dim Origine As String
    Dim Destination As String
    Dim Nom_Fichier_destination As String
    Dim Chemin_destination As String

    Origine = CheminFichierComplet
    Destination = Dossier_destination_copie_nas & Origine.Replace (EditText11a.Text, "")
   
    Nom_Fichier_destination = Destination.SubString2 (Destination.LastIndexOf ("/")+1, Destination.Length )
   
    Chemin_destination = Origine.Replace (EditText11a.Text, "")
    Chemin_destination = Chemin_destination.SubString2 (0,Chemin_destination.LastIndexOf ("/")) & "/"

    File.MakeDir (Chemin_final_copie_dossier_nas, Dossier_destination_copie_nas & Chemin_destination)
   
    FTP2.DownloadFile (Origine, False, Chemin_final_copie_dossier_nas & Dossier_destination_copie_nas & Chemin_destination, Nom_Fichier_destination)
    Label20a.Text = "à copier '" & Origine & "'" 
End Sub

Sub FTP2_DownloadCompleted (ServerPath As String, Success As Boolean)
    'Log(ServerPath & ", Success=" & Success)
    'If Success = False Then Log(LastException.Message)
    If Success = True Then
        Label20a.Text =  "Fichier '" & ServerPath & "' téléchargé et copié."  
    End If
End Sub   

Sub FTP2_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
   
    Dim Resultat As String
   
    If Success = False Then
        Log(LastException)
    Else
        For i = 0 To Folders.Length - 1
            FTP2.List (ServerPath &  "/" & Folders(i).Name)
        Next
        For i = 0 To Files.Length - 1
            Resultat = ServerPath & "/" & Files(i).Name
            Copier_ce_fichier (Resultat)
       Next
      Mise_a_jour_listview_dongle
      Mise_a_jour_listview_clef
   End If

End Sub
 

DonManfred

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/t...ures-and-what-to-do-with-this-filelist.40560/
See the methods in this thread. It may be of inspiration for you.

The point is;

You need to create a list for files you download.
fill the list with all files to download and then download the first from the list.
In the completed sub you then remove the first entry from this list and download the new first one.
In the completed sub you then remove the first entry from this list and download the new first one.
[and so on]
If the list is empty then all files are downloaded
 
Upvote 0
Top