iOS Question [SOLVED] - iNET - ftp issue

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

I have implemented the ftp component for the purpose of uploading a log file to a FileZilla server. I have already done this on b4a with much success. However on B4i as I am unable to close the connection when then job is completed,(I can see the connection open on the server) , I have to wait for the server to close the connection. If I let this happen and try to send another file upload it does not happen. It seems to become available again after 3-5 mins.

I have read the after each execution the connection is closed, this does not appear to happen for me and I have to wait for the server to timeout the connection.

Ideas ?

Regards

John.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is expected to reuse the same connection.

This code works fine here:
B4X:
ftp.PassiveMode = True
For i = 1 To 10
    File.WriteString(xui.DefaultFolder, i, i)
    Wait For (ftp.UploadFile(xui.DefaultFolder, i, False, target & i)) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", " & Success)
Next
If it doesn't work with your server then your best option is to create a new FTP object (Dim + Initialize) every time.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
This the func:

B4X:
Sub send_logs_ftp
        
    Dim lfile As String
    lfile = $"iSOS_${mod_functions.make_date_string(DateTime.Now)}_${APPSET.IMEI}.log"$
    ' // cleanup filename
    lfile = lfile.Replace("/",".")
    lfile = lfile.Replace(":",".")
    lfile = lfile.Replace(" ","_")
    
    mod_functions.writeLog($"Sending log file ${lfile}"$)
    Try
        ' // create log file name
        File.Copy(File.DirDocuments,"vsos.log",File.DirDocuments,lfile)
        
        Dim ftp    As FTP
        ftp.Initialize("ftp", "xxxxx.islesystems.com", 21, "xxxxx", "xxxxxxx")
        ftp.PassiveMode = True

        Dim sftp As Object = ftp.UploadFile(File.DirDocuments, lfile, True, "/" & lfile)
        Wait For (sftp) ftp_UploadCompleted (ServerPath As String, Success As Boolean)

        If Success Then
            mod_functions.writeLog($"${ServerPath} was uploaded successfully"$)
            hd.ToastMessageShow("File was uploaded successfully",False)
        Else
            mod_functions.writeLog($"${ServerPath} - Error uploading file"$)
            hd.ToastMessageShow("Error uploading file",False)
        End If        
        File.Delete(File.DirDocuments,lfile)
        
        ftp.SendCommand("QUIT","")  <- this is new to see if the connection gets closed, but same issue.
    Catch
        mod_functions.writeLog($"send_logs::Error - ${LastException.Message} "$)
    End Try
    
    
End Sub

I am already doing as you suggested. I added a QUIT commend to see if it released it but the same issue still prevails.

Regards

John.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
I can do lots of uploads, but once I stop doing uploads and the FileZilla server terminated the connection that when the issue arises. The func was in main I have now put into a class to see if that makes a difference when the server closes the connection.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Just did the test, and after the server closed the connection, and a new send was initiated, it failed. these are the logs from the app showing the failure:

B4X:
02/04/2021 13:58:05.769 - Atlas iSOS - Sending log file iSOS_2021.02.04_13.58.05_353837081304527.log
02/04/2021 13:59:49.907 - Atlas iSOS - /iSOS_2021.02.04_13.58.05_353837081304527.log - Error uploading file
Class (b4i_cls_send_logs) instance released.
Event target instance was released: ftp_commandcompleted::::
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
1. Yes, but only if the connection on the server has not been closed.
2. Yes, see the logs.

B4X:
02/04/2021 14:04:47.677 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.04.47_353837081304527.log
02/04/2021 14:04:48.213 - Atlas iSOS - /iSOS_2021.02.04_14.04.47_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:04:56.718 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.04.56_353837081304527.log
02/04/2021 14:04:57.016 - Atlas iSOS - /iSOS_2021.02.04_14.04.56_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:04:59.287 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.04.59_353837081304527.log
02/04/2021 14:04:59.613 - Atlas iSOS - /iSOS_2021.02.04_14.04.59_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:05:01.689 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.05.01_353837081304527.log
02/04/2021 14:05:01.996 - Atlas iSOS - /iSOS_2021.02.04_14.05.01_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:05:04.046 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.05.04_353837081304527.log
02/04/2021 14:05:04.361 - Atlas iSOS - /iSOS_2021.02.04_14.05.04_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:05:06.214 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.05.06_353837081304527.log
02/04/2021 14:05:06.519 - Atlas iSOS - /iSOS_2021.02.04_14.05.06_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:05:08.378 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.05.08_353837081304527.log
02/04/2021 14:05:08.684 - Atlas iSOS - /iSOS_2021.02.04_14.05.08_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:05:10.640 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.05.10_353837081304527.log
02/04/2021 14:05:10.955 - Atlas iSOS - /iSOS_2021.02.04_14.05.10_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:05:13.017 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.05.13_353837081304527.log
02/04/2021 14:05:13.321 - Atlas iSOS - /iSOS_2021.02.04_14.05.13_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:05:16.068 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.05.16_353837081304527.log
02/04/2021 14:05:16.392 - Atlas iSOS - /iSOS_2021.02.04_14.05.16_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:07:21.289 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.07.21_353837081304527.log
02/04/2021 14:08:06.584 - Atlas iSOS - /iSOS_2021.02.04_14.07.21_353837081304527.log - Error uploading file
Class (b4i_cls_send_logs) instance released.
02/04/2021 14:10:14.504 - Atlas iSOS - Sending log file iSOS_2021.02.04_14.10.14_353837081304527.log
02/04/2021 14:10:15.041 - Atlas iSOS - /iSOS_2021.02.04_14.10.14_353837081304527.log was uploaded successfully
Class (b4i_cls_send_logs) instance released.

The red entry is the failure after the server closed the connection. The green is the next upload that was successful after a short period of time.
I wonder is it the FileZilla Server 0.9.60 beta that is causing this. Do you have the same issue as me with the same test ? What FTP server are you using ?

Regards

John.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
I changed the connection timeout to 10 seconds on FileZilla and it appear to be working fine now, just thought you would like to know.
 
Upvote 0
Top