Android Question FTP large file problem

Discussion in 'Android Questions' started by Nitro, Jul 26, 2015.

  1. Nitro

    Nitro Member Licensed 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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    FTP is always executed in a separate thread.

    Can you post the uploading code? Does it happen if you do not handle the progress events?
     
  3. Nitro

    Nitro Member Licensed User

    Code:
    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: Jul 26, 2015
  4. Erel

    Erel Administrator Staff Member Licensed User

    What is mwSword?

    Is the UI frozen during the upload?
     
  5. Nitro

    Nitro Member Licensed 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.
     
  6. Nitro

    Nitro Member Licensed User

    When the upload is finished, the GUI comes back to life.
     
  7. DonManfred

    DonManfred Expert Licensed User

    how is this implemented in java? Is it a thread?
     
  8. Nitro

    Nitro Member Licensed 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.
     
  9. DonManfred

    DonManfred Expert Licensed 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
     
  10. Nitro

    Nitro Member Licensed User

    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.
     
  11. DonManfred

    DonManfred Expert Licensed User

    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
     
  12. Nitro

    Nitro Member Licensed User

    Sorry, can't do that. Project is quite large and it's company property.
    This isn't a hobby project.
     
  13. Nitro

    Nitro Member Licensed 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.
     
  14. DonManfred

    DonManfred Expert Licensed User

    Code:
    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
     
  15. DonManfred

    DonManfred Expert Licensed User

    another test
     
    lemonisdead and Erel like this.
  16. Nitro

    Nitro Member Licensed User

    The Event FTP_UploadCompleted works fine, it's the FTP_UploadProgress I have problems with.
     
  17. DonManfred

    DonManfred Expert Licensed User

    You can see a working sample in Post #14 and a large upload-result in #15
     
    lemonisdead likes this.
Loading...