Android Question FTP large file problem

Nitro

Member
Licensed User
Longtime User
I have created an app which uploads small to larger media files.
There's possibly videos, pictures, audio and text files zipped in one file, transferred with FTP lib (NET) or Auto_FTP as I'm trying to find a solution.
If the file going to be transferred is larger than 10Mb the transfer status updates stops and hangs the device but the background process continues and the FTP transfers until finished but the device become unresponsive.
Is there a way to put the transfer(FTP object with it's subs and status update) in to a separate thread with semaphore activities?
 

Nitro

Member
Licensed User
Longtime User
B4X:
FTP.Initialize("FTP" ,mwGlobals.FTPServer, mwGlobals.FTPPort, mwGlobals.FTPUser , mwGlobals.FTPUserPassword)    'NET lib
      
FTP.PassiveMode = True
      
        If mwGlobals.FTPSSL = True Then
            FTP.UseSSL = True
            mwTrust.InitializeAcceptAll
            FTP.SetCustomSSLTrustManager(mwTrust)
        End If

  
Dim mwEncrFileZip As String = strFileName
mwEncrFileZip = mwSword.Encrypt(strFileName)
FTP.UploadFile( mwGlobals.ZipDirectory,  strFileName, False, strFileName )
DoEvents

I use the corresponding Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long) event to trap progress.

The file is sent properly, but the device is hung, can't do anything, early on when transfer commence, the event is triggered but after 10Mb or so, the event becomes "silent".
I have to get some notification on progress for upload. Without it, I'm sailing blind.

Btw, Hi Erel and thanks for a great tool. :)
 
Last edited:
Upvote 0

Nitro

Member
Licensed User
Longtime User
:) It's my own encryption, RijnDael with Swordfish AES in NET and ported over to B4A, Android.
Don't pay any attention to it, as you can see in the code, I don't use it but I will as soon as I can get an "unfrozen" GUI.
***Is the UI frozen during the upload?****
Sort of, it freezes but not indefinitely, if I tap any system function like back or applications, nothing happens for a VERY long time, but it does react at one point or another.
I use Samsung Note4, Tab S10, S5 and Galaxy Tab 7.7 to test and they all behave the same way.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Nitro

Member
Licensed User
Longtime User
It collects the physical file from the filename which is stored in a predefined folder and creates another file but encrypted with a key, up to 48 chars long.
Optional erase of the original file. so the answer is no, it's more a method than a threaded sub. The returned result is the path and the new name of the Encrypted file.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How long does the method run till it finishes? Maybe this is the problem which causes the hang...

Most probably it is a good idea to rework it to be used async instead of a simple method-call....

So after mwSword.Encrypt(strFileName) you wait for the event encrytionfinished (or whatever name the event may have). And in this eventsub you then start the upload.

btw: you probably should remove the doevents
 
Upvote 0

Nitro

Member
Licensed User
Longtime User
How long does the method run till it finishes? Maybe this is the problem which causes the hang...

Most probably it is a good idea to rework it to be used async instead of a simple method-call....

So after mwSword.Encrypt(strFileName) you wait for the event encrytionfinished (or whatever name the event may have). And in this eventsub you then start the upload.

btw: you probably should remove the doevents
I don't use the encryption at the moment and I have tried with and without DoEvent.
I have even created a separate project with only the FTP code in it but not getting closer to a solution.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I have even created a separate project with only the FTP code in it but not getting closer to a solution.
may you want to upload your new project? In the ide use File -> Export as zip and upload the project. overwrite your credentials... I can use my own on my ftp-server
 
Upvote 0

Nitro

Member
Licensed User
Longtime User
Sorry, can't do that. Project is quite large and it's company property.
This isn't a hobby project.
 
Upvote 0

Nitro

Member
Licensed User
Longtime User
My focus right now is to solve the FTP problems with larger binary file uploads.
I could give you the FTP project I have tried with but it's more or less based on samples here.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    s = ""
    old = "ddsmerlk439"
    If FirstTime Then
        FTP.Initialize("FTP", "host", 21, "user", "password")
    End If
   
    FTP.UploadFile(File.DirAssets,"guide.zip",False, "/guide.zip")
End Sub

Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
  s = "Uploaded " & (TotalUploaded / 1024 / 1024) & "MB"
  If Total > 0 Then s = s & " out of " & (Total / 1024 / 1024) & "MB"
  If s.EqualsIgnoreCase(old) Then
    Else
        old = s
        Label1.Text = s
        Log(s)
    End If
End Sub
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
  Log(ServerPath & ", Success=" & Success)
  Label1.Text = "Upload (18mb) completed!"
    If Success = False Then Log(LastException.Message)
End Sub
[..]
Uploaded 18.3583984375MB
Uploaded 18.359375MB
Uploaded 18.3594331741333MB
/guide.zip, Success=true
** Activity (main) Pause, UserClosed = true **
 
Upvote 0

Nitro

Member
Licensed User
Longtime User
The Event FTP_UploadCompleted works fine, it's the FTP_UploadProgress I have problems with.
 
Upvote 0
Top