iOS Question FTP - slow download

Discussion in 'iOS Questions' started by jhagerup, Jul 11, 2015.

  1. jhagerup

    jhagerup Member Licensed User

    I'm downloading a number of png's and have experienced this:

    When I don't use "persistConnection" it goes fast, but requires as many connection pr. account as the number of files !

    Using "persistConnection" there is a delay at about 30 seconds between each file.

    (Nearly) same code in B4A is as fast as not "persistConnection" in B4i.

    Comments on code: the files to download is found in a database (DBResult) and is saved in a KeyValueStore (kvs) for later use.

    Code:
    Sub process_getallmain(result As DBResult)
        
    Dim but As String
        
    Dim background As String
        
    Dim link As String
        pendingDownloadCount = 
    0
        ftpService.Initialize(
    "FTP",serverIP,21,"apps","apps")

        
    Dim no As NativeObject = ftpService
        no.GetField(
    "server").SetField("persistConnection"True)

        
    For Each records() As Object In  result.Rows
            but=records(result.Columns.Get(
    "button"))
            background = records(result.Columns.Get(
    "background"))
            link = records(result.Columns.Get(
    "link"))
            kvs.PutSimple(but & 
    "_background", background)   
            kvs.PutSimple(but & 
    "_link", link)
            ftpList.Add(background)
            pendingDownloadCount = pendingDownloadCount +
    1
        
    Next
        getButtonImage(ftpList.Get(pendingDownloadCount - 
    1))   
    End Sub

    Sub getButtonImage(background As String)
        ftpService.DownloadFile(
    "/apps/1/" & background,False,File.DirLibrary, background)
    End Sub

    Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
        
    If Success Then 
            
    Log(ServerPath & " - OK")
            pendingDownloadCount = pendingDownloadCount - 
    1
            
    If pendingDownloadCount = 0 Then 
                PrepareAll
                hd.ProgressDialogHide
            
    Else
                getButtonImage(ftpList.Get(pendingDownloadCount - 
    1))               
            
    End If
        
    Else
            
    Log(ServerPath & " - " & LastException.Description)
            getButtonImage(ftpList.Get(pendingDownloadCount - 
    1))       
        
    End If
    End Sub
    Attached: Application-logs & FTP-server-log (csv)
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    If you are using the same ftp object then it will create a single connection. It will reconnect each time. However it doesn't create any load on the server.
     
  3. jhagerup

    jhagerup Member Licensed User

    I am only using one ftp object. The problem is that B4i causes a 30 seconds delay between each file in persistent mode. There is no delay in B4A, and it seems to be persistent - according to ftp-server log. Same timeout as for the delayed ftp-session logout ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Does it work properly if you don't set the persistConnection field?
     
  5. jhagerup

    jhagerup Member Licensed User

    Yes, but it makes a connection for each file. When more files than allowed sessions, the download fails until one of the open connections logs out - after about 30 secs. - about the same delay as between files in persistant mode
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't see this behavior here. Maybe you can configure your ftp server to close disconnected clients automatically.

    You can try to use persistent mode and send QUIT with FTP.SendCommand after each download.
     
  7. jhagerup

    jhagerup Member Licensed User

    With pesistent mode and a QUIT command the behavior changed to:
    login - read - login - logout - 30 secs delay - read - login - logout - 30 secs delay - read......
    According to the ftp-log. The "next" login seems to happen before the "last" logout and the delay seems to relate to the read.
    And I have no "disconnect clients automatically" settings in my ftp-server.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Is this FTP server accessible through the internet? If yes then I can try it myself if you like.
     
  9. jhagerup

    jhagerup Member Licensed User

    Yes: 94.145.79.229 - apps - apps and there are a couple of .png
    But... it works fine in B4A, so I don't think that it's a server problem.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    I've tried it with this code:
    Code:
    Sub Process_Globals
       
    Public App As Application
       
    Public NavControl As NavigationController
       
    Private Page1 As Page
       
    Private ftp As FTP
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.Title = 
    "Page 1"
       Page1.RootPanel.Color = 
    Colors.White
       NavControl.ShowPage2(Page1, 
    True)
       
    ftp.Initialize("ftp""94.145.79.229"21"apps""apps")
       
    ftp.PassiveMode = True
       
    ftp.List("/apps/1")
    End Sub

    Sub ftp_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
       
    For Each fe As FTPEntry In Files
         
    If fe.Size < 100000 Then ftp.DownloadFile("/apps/1/" & fe.Name, FalseFile.DirTemp, fe.Name)
       
    Next
    End Sub

    Sub ftp_DownloadCompleted (ServerPath As String, Success As Boolean)
       
    Log($"$Time{DateTime.Now}: ${ServerPath}, success = ${Success}"$)
    End Sub
    The output is:
    Tested on the simulator. It looks fine.
     
    TWCoder likes this.
  11. jhagerup

    jhagerup Member Licensed User

    This runs fine with me too, and the project too.

    Thanks
     
Loading...