Spanish b4i descargar ftp

Jorge Sanz

Member
Licensed User
Hola,

Tengo el siguiente codigo para descargar archivos de ftp que me funciona perfectamente con B4A. Pero en B4i no me realiza descargas, alguien puede ayudarme!!!!!

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
 

Descartex

Well-Known Member
Licensed User
Longtime User
Muy buenas:
Como se explica en este post:
https://www.b4x.com/android/forum/threads/ats-app-transport-security.74281/#content
se bloquea el acceso a urls directamente desde la app, con lo cual deberias añadir el dominio desde el que necesitas descargar a la lista segura, algo asi:
B4X:
#PlistExtra: <key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><false/>
#PlistExtra: <key>NSExceptionDomains</key><dict>
'list the excluded domains (example.com and b4x.com)
#PlistExtra: <key>http://xxx.com/ary</key><dict><key>NSIncludesSubdomains</key><true/><key>NSExceptionAllowsInsecureHTTPLoads</key><true/></dict>
'#PlistExtra: <key>b4x.com</key><dict><key>NSIncludesSubdomains</key><true/><key>NSExceptionAllowsInsecureHTTPLoads</key><true/></dict>
'end of excluded domains
#PlistExtra: </dict>
#PlistExtra: </dict>

Un saludo.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…