iOS Question download ftp

Jorge Sanz

Member
Licensed User
Hello,

I have the following code to download ftp files that works perfectly with B4A. But B4i does not download, someone can help me !!!!!


B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
ftp.Initialize("FTP", "ftp.xxxx.com", 21, "xx", "xx")
    ftp.PassiveMode=True
    
    todownload.Initialize
    
    File.MakeDir(File.DirDefaultExternal ,"0040")
    Dim rutades As String
    rutades="html/ary/banners/0040"
    Log (rutades)
    
    ftp.List(rutades)
End Sub



Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    Log(ServerPath)
    Dim rutaftp,rutamovil As String
    If Success = False Then
        Log(LastException)
    Else
        
        
                For i = 0 To Folders.Length - 1
                    Log(Folders(i).Name)
                Next
                For i = 0 To Files.Length - 1
            
                    Log(Files(i).Name)
                    rutamovil= File.DirDefaultExternal & "/0040"
            
                    todownload.Add("http://xxx.com/ary/banners/0040/"& Files(i).Name)
                
                    'Log(todownload)
                Next
                If todownload.Size > 0 Then
                    Dim furl As String = todownload.Get(0)
                    Log("Download: "&furl)
                    Dim j As HttpJob
                    j.Initialize("DownloadFile",Me)
                    j.Tag = furl
                    j.Download(furl)
                End If
                
        
            
                        
        

    End If
End Sub


Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
    
        Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
        Select Job.JobName
            
        
            Case "DownloadFile"
                Dim p As String = Job.Tag
                Dim OutStream As OutputStream
                Log("DownloadReady: "&Job.Tag)
                OutStream = File.OpenOutput(File.DirDefaultExternal & "/0040" , GetFilename(p), False)
                File.Copy2(Job.GetInputStream,OutStream) ' save the file
                OutStream.Close
                Log(GetFilename(p)&" is written to "&File.DirDefaultExternal)
                ' Remove the first job from queue
                If todownload.Size > 0 Then
                    todownload.RemoveAt(0)
                End If

                ' Check if there are more files to download. If yes. Download them
                If todownload.Size > 0 Then
                    Dim furl As String = todownload.Get(0)
                    Log("Download: "&furl)
                    Dim j As HttpJob
                    j.Initialize("DownloadFile",Me)
                    j.Tag = furl
                    j.Download(furl)
                Else
                    Msgbox ("Fin","")
                    'LogColor("======================================",Colors.Green)
                    'LogColor("===== ALL FILES FROM QUERE     =======",Colors.Green)
                    'LogColor("===== ARE FINISHED DOWNLOADING =======",Colors.Green)
                    'LogColor("======================================",Colors.Green)
                    'DESCARGAR FRASES
                    'File.MakeDir(File.DirDefaultExternal, "frases")
                    'descargaactiva="frases"
                    'ftp.List("html/ary/frases")
                End If
        
                
        
        End Select
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub GetFilename(fullpath As String) As String
    Return fullpath.SubString(fullpath.LastIndexOf("/") + 1)
End Sub
 

Jorge Sanz

Member
Licensed User
Hello,
thanks for answering, tomorrow I have to deliver the project and I am desperate.
The previous code works correctly in IOS to download a single file (ftp_downloadcompleted).
I'm working remotely and I can not debug step by step, I just know that the value of Success in ftp_listcompleted is always False.

thanks for helping
 
Upvote 0
Top