Android Question Ftp cannot upload files after about 30 minutes

Mscal

Member
Licensed User
Main code is:
B4X:
Sub Process_Globals
    Private timer1 As Timer
    Private timer2 As Timer
End Sub

Sub Globals
    Public UDPSocket1 As UDPSocket
    Public xdata() As Byte
    Public xPacket As UDPPacket
    Dim phonewake1 As PhoneWakeState
    Dim ftp1 As FTP

End Sub

Sub Activity_Resume
    Activity.LoadLayout("Form1")
    timer1.Initialize("timer1",2000)
    timer2.Initialize("timer2",10000) 'if Ftp cannot upload in 10s then close it
    UDPSocket1.Initialize("UDP", 0, 8000)
    phonewake1.KeepAlive(True)
    phonewake1.PartialLock
    timer1.Enabled=True
End Sub

Sub timer1_tick
        dim photoname as string
        Dim i As Long=DateTime.now

        '======================
        'codes to creat files is covered
        '======================

        photoname="1" & Twoblack(DateTime.GetDayOfMonth(i)) & Twoblack(DateTime.GetHour(i)) & Twoblack(DateTime.GetMinute(i)) & Twoblack(DateTime.GetSecond(i))

    ftp1.Initialize("ftp1","IP",21,"User","Password")
    ftp1.UploadFile(dir,filename,False,"/" & filename)
    xdata =("4" & filename).GetBytes("UTF8")
    xPacket.Initialize(xdata, "IP", Port)
    UDPSocket1.Send(xPacket)
    ToastMessageShow(photoname & " UPLOADing" & successnum ,True)
    timer2.enable=true
    timer1.enable=false
End Sub

Sub timer2_tick
    ftp1.CloseNow
    timer1.Enabled=True
    ToastMessageShow(sendfilename & "UPLOAD CRASH",True)
End Sub

Sub ftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success=True Then
        File.Delete(dir,filename)
        xdata =(filename).GetBytes("UTF8")
        xPacket.Initialize(xdata, "IP", Port)
        UDPSocket1.Send(xPacket)
        ToastMessageShow(filename & " DONE",True)
        timer1.Enabled=True
        timer2.Enabled=False
    End If
End Sub

I tested many times,Ftp cannot upload files after about 30 minutes(cannot recieved filename [xdata =(filename).GetBytes("UTF8")]).And i can always received "4" & filename [xdata =("4" & filename).GetBytes("UTF8")] so the network is ok.

What caused it?


Here is server screen.
1.jpg
 
Last edited:

Mscal

Member
Licensed User
There are several mistakes in this code. Why are you initializing the FTP object multiple times?

Initialize it once in Activity_Create when FirstTime is true or better move it to the starter service.
In order to find the mistake,i tried Initialize it in Activity_resume and in timer too.
And now i find that when "#FullScreen: false" the ftp work well
 
Upvote 0
Top