iOS Question FTP - slow download

jhagerup

Member
Licensed User
Longtime 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.

B4X:
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)
 

Attachments

  • Applicaion-logs.txt
    4 KB · Views: 208
  • FTP-sever-log.txt
    6.7 KB · Views: 226

jhagerup

Member
Licensed User
Longtime 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 ?
 
Upvote 0

jhagerup

Member
Licensed User
Longtime 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
 
Upvote 0

jhagerup

Member
Licensed User
Longtime 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.
 
Upvote 0

jhagerup

Member
Licensed User
Longtime 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.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tried it with this code:
B4X:
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, False, File.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:
Application_Start
Application_Active
11:12:34: /apps/1/calender.png, success = 1
11:12:35: /apps/1/email.png, success = 1
11:12:37: /apps/1/fitness.png, success = 1
11:12:39: /apps/1/kniv+gaffel.png, success = 1
11:12:40: /apps/1/navigation.png, success = 1
11:12:42: /apps/1/phone.png, success = 1
11:12:43: /apps/1/q.png, success = 1
11:12:45: /apps/1/sgf2.png, success = 1
11:12:46: /apps/1/skalsdata.png, success = 1
11:12:48: /apps/1/skytteforeningen.png, success = 1
11:12:50: /apps/1/valkyrien.png, success = 1
11:12:52: /apps/1/web.png, success = 1

Tested on the simulator. It looks fine.
 
Upvote 0
Top