Android Question FTP Raise and Rel 7.01

MarcoRome

Expert
Licensed User
Longtime User
I've resumed for some changes an application developed with version 6.50. With version 6.50 worked smoothly
By compiling the same with version 7.01 I noticed that the FTP_DeleteCompleted event is not executed ( also if i add a break in debug, see where i write "'Here i add Break" )


Original Code:
B4X:
If Starter.tipo_foto = "front" Then
    If carico_front_picture = False Then
        Chooser.Initialize("chooser")
        Chooser.Show("image/*", "Select Picture")
    Else
        'Invio tramite FTP
        FTP.Initialize("FTP", "ftp.xxxx", 21, "yyyyyuser", "pwuser")
        FTP.DeleteFile("/hotelguru/" & filenameresize )
         
            If vp.IsInitialized Then 'Here i add Break
                    vp.DestroyEngine
                    vp.Initialize("vp",False)
                    pnl_foto.AddView(vp, 0, 0, pnl_foto.Width, pnl_foto.Height)
                    vp.CompressQuality = 100
                    vp.ZoomEnabled = False
                    vp.Transition = vp.Transition.CubeHorizontal
                    vp.ProgressBarVisible = True
                  

            End If
            btn_upload_Click
            End If
        End If
Else
        'SE ROOM
        Chooser.Initialize("chooser")
        Chooser.Show("image/*", "Select Picture")
End If
End Sub
.....
Sub FTP_DeleteCompleted(ServerPath As String, Success As Boolean)
    Log("FTP_DELETE: " &ServerPath & ", Success=" & Success)
If Starter.tipo_foto = "front" Then
        ExecuteRemoteQuery($"DELETE FROM hotelguru_picture where photo_room = '${filenameresize}'"$,"cancellafoto")
        filenameresize = ""
        carico_front_picture = False
    Else
        Log($"DELETE FROM hotelguru_picture where photo_room = '${foto_selezionata}'"$)
        ExecuteRemoteQuery($"DELETE FROM hotelguru_picture where photo_room = '${foto_selezionata}'"$,"cancellafoto")
        foto_selezionata = ""
      
    End If
    FTP.Close
End Sub


After trying several times to run this part of the code i added Wait for:

B4X:
If Starter.tipo_foto = "front" Then
    If carico_front_picture = False Then
        Chooser.Initialize("chooser")
        Chooser.Show("image/*", "Select Picture")
    Else
        'Invio tramite FTP
        FTP.Initialize("FTP", "xxxx", 21, "userxxxx", "pwuserxxxxx")
        FTP.DeleteFile("/hotelguru/" & filenameresize )
        Wait For FTP_DeleteCompleted(ServerPath As String, Success As Boolean)
            If Success Then
                Log("FTP_DELETE: " &ServerPath & ", Success=" & Success)
                If Starter.tipo_foto = "front" Then
                    ExecuteRemoteQuery($"DELETE FROM hotelguru_picture where photo_room = '${filenameresize}'"$,"cancellafoto")
                    filenameresize = ""
                    carico_front_picture = False
                Else
                    Log($"DELETE FROM hotelguru_picture where photo_room = '${foto_selezionata}'"$)
                    ExecuteRemoteQuery($"DELETE FROM hotelguru_picture where photo_room = '${foto_selezionata}'"$,"cancellafoto")
                    foto_selezionata = ""
          
                End If
                FTP.Close
          
            If vp.IsInitialized Then
                    vp.DestroyEngine
                    vp.Initialize("vp",False)
                    pnl_foto.AddView(vp, 0, 0, pnl_foto.Width, pnl_foto.Height)
                    vp.CompressQuality = 100
                    vp.ZoomEnabled = False
                    vp.Transition = vp.Transition.CubeHorizontal
                    vp.ProgressBarVisible = True
                  

            End If
            btn_upload_Click
            End If
        End If
Else
        'SE ROOM
        Chooser.Initialize("chooser")
        Chooser.Show("image/*", "Select Picture")
End If
End Sub

So work without problem.
But the question is why doesn't work the event in the "old way" ?
Thank you
Marco
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Hi Erel, sure...

Look this movie, if i add breakpoint on Button1_Click, i would expect to see in the log window this result:
Log("FTP_DELETE FROM RAISE: " &ServerPath & ", Success=" & Success)
because in the folder the file is deleted.




Example Code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Chooser As ContentChooser
    Dim FTP As FTP
    Dim ftp_address As String = "ftp.xxxx"
    Dim user_ftp As String = "yyyyy"
    Dim pw_ftp As String = "zzzzz"
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Dim carico_front_picture As Boolean = True
    Dim tipo_foto As String = "front"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
   
If tipo_foto = "front" Then
    If carico_front_picture = False Then
        Chooser.Initialize("chooser")
        Chooser.Show("image/*", "Select Picture")
    Else
        'Invio tramite FTP
        FTP.Initialize("FTP", ftp_address, 21, user_ftp, pw_ftp)
        FTP.DeleteFile("/hotelguru/test.jpg" )
'            Wait For FTP_DeleteCompleted(ServerPath As String, Success As Boolean)
'            If Success Then
'                Log("FTP_DELETE FROM WAIT: " &ServerPath & ", Success=" & Success)
'                FTP.Close
'                carico_front_picture = False
'                Button1_Click
'            End If
       Button1_Click
    End If
Else
        'SE ROOM
        Chooser.Initialize("chooser")
        Chooser.Show("image/*", "Select Picture")
End If
End Sub




Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
           
    '.....
    End If
End Sub



Sub FTP_DeleteCompleted(ServerPath As String, Success As Boolean)
    Log("FTP_DELETE FROM RAISE: " &ServerPath & ", Success=" & Success)
    carico_front_picture = False
    Button1_Click
    FTP.Close
End Sub

Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tested it with this code and the event is raised properly:
B4X:
Sub Process_Globals
   Private ftp As FTP
End Sub

Sub Service_Create
   ftp.Initialize("ftp", "aaa.com", 21, "xxx", "xxxx")
   ftp.DeleteFile("/somefile")
End Sub

Sub FTP_DeleteCompleted (ServerPath As String, Success As Boolean)
   Log("delete")
   Log(Success)
End Sub
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I've tested it with this code and the event is raised properly:
B4X:
Sub Process_Globals
   Private ftp As FTP
End Sub

Sub Service_Create
   ftp.Initialize("ftp", "aaa.com", 21, "xxx", "xxxx")
   ftp.DeleteFile("/somefile")
End Sub

Sub FTP_DeleteCompleted (ServerPath As String, Success As Boolean)
   Log("delete")
   Log(Success)
End Sub

if you have only this code work without problem
ftp.Initialize("ftp", "aaa.com", 21, "xxx", "xxxx")
ftp.DeleteFile("/somefile")

but if you add another code type:

B4X:
FTP.Initialize("FTP", ftp_address, 21, user_ftp, pw_ftp)
FTP.DeleteFile("/hotelguru/test.jpg" )
.....
Button1_Click

The file is deleted but the event isnt raise.
Anyway with Wait For work without problem
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Moved to the questions forum as it doesn't look like a bug.

You are initializing FTP again in Button1_Click for some reason. This is a mistake.
Yes right.
But i can't explain why it worked first.
And because if i insert a breakpoint on the Button1_Click ( in this way i pause the program here, the Button1_Click isn't executed, right ?) call it still does not run.
 
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Anyway yes is clear the next time i will move my code in FTP_DeleteCompleted.
So work without problem or even better, having "Wait For"
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Anyway yes is clear the next time i will move my code in FTP_DeleteCompleted.
So work without problem or even better, having "Wait For"

I have had this issue some times ago when setting breakpoints at the last line of a sub or just like you after a command which runs a asynchronus command (I can't describe better). One time I got crazy because a Scrollview wasn't scrolling to the end because of that. Maybe the debugger prevents it.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I have had this issue some times ago when setting breakpoints at the last line of a sub or just like you after a command which runs a asynchronus command (I can't describe better). One time I got crazy because a Scrollview wasn't scrolling to the end because of that. Maybe the debugger prevents it.
Yes will be so.
Also because if you run step by step debug, when finish Sub go in FTP_DeleteCompleted ( also if delete the file right after the method DeleteFile ) the event is raised after the sub is end.
 
Upvote 0
Top