Android Question FTP Unable to List operation

rdkartono

Member
Licensed User
Longtime User
I used Net library version 1.81 on B4A 12.80

I use FTP with code as below
FTP initialization:
ftp_server_confirmed = False
    Dim sock As Socket
    sock.Initialize("sock")
    sock.Connect(host,port, 5000)
    Wait For sock_Connected (Successful As Boolean)
    sock.Close
    If Successful Then
        ftp.Initialize("ftp",host,port,username,password)
        Log($"FTP initialized with host=${host}, port=${port}, username=${username}, password=${password}"$)
        ftp.PassiveMode = True
        ftp.UseSSL = False
        ftp.UseSSLExplicit = False
        
        Dim obj As Object = ftp.SendCommand("PWD","")
        Wait For (obj) ftp_CommandCompleted (Command As String, Success As Boolean, ReplyCode As Int, ReplyString As String)
        Log($"Command = ${Command}, Success = ${Success}, ReplyCode = ${ReplyCode}, ReplyString = ${ReplyString}"$)
        ftp_server_confirmed = Success
        If Success Then
            mHost = host
            mPort = port
            mUserName = username
            mPassword = password
        End If
        Disconnect
        Return Successful
    Else
        Log($"Unable to initialize FTP with host=${host}, port=${port}"$)
    End If
    Return False

This initialization can send command PWD and get proper response .
VSFTPD log showed as
VSFTPD log on PWD:
Tue Feb 27 08:48:15 2024 [pid 154188] CONNECT: Client "202.137.6.19"
Tue Feb 27 08:48:15 2024 [pid 154188] FTP response: Client "202.137.6.19", "220 (vsFTPd 3.0.5)"
Tue Feb 27 08:48:15 2024 [pid 154190] CONNECT: Client "202.137.6.19"
Tue Feb 27 08:48:15 2024 [pid 154190] FTP response: Client "202.137.6.19", "220 (vsFTPd 3.0.5)"
Tue Feb 27 08:48:15 2024 [pid 154190] FTP command: Client "202.137.6.19", "USER fromthesea"
Tue Feb 27 08:48:15 2024 [pid 154190] [fromthesea] FTP response: Client "202.137.6.19", "331 Please specify the password."
Tue Feb 27 08:48:15 2024 [pid 154190] [fromthesea] FTP command: Client "202.137.6.19", "PASS <password>"
Tue Feb 27 08:48:16 2024 [pid 154189] [fromthesea] OK LOGIN: Client "202.137.6.19"
Tue Feb 27 08:48:16 2024 [pid 154191] [fromthesea] FTP response: Client "202.137.6.19", "230 Login successful."
Tue Feb 27 08:48:16 2024 [pid 154191] [fromthesea] FTP command: Client "202.137.6.19", "PWD"
Tue Feb 27 08:48:16 2024 [pid 154191] [fromthesea] FTP response: Client "202.137.6.19", "257 "/" is the current directory"

Then I issue List command as below
FTP List command:
Public Sub Check_Files_On_FTPServer(path As String) As ResumableSub
    Dim result As JsonArray
    result.InitializeEmpty
    
    If ftp_server_confirmed Then
        ftp.Initialize("ftp",mHost,mPort,mUserName,mPassword)
        If ftp.IsInitialized Then
            Log("about to Check_Files_On_FTPServer on path "&path)
        
            Wait For (ftp.List(path)) ftp_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
            Log("Check_Files_On_FTPServer path = "&ServerPath&", result = "&Success&", File length = "&Files.Length&", Folder length = "&Folders.Length)
            If Success Then
                lastresult.InitializeEmpty
                If (Folders<>Null And Folders.Length>0) Then
                    For Each fe As FTPEntry In Folders
                        Dim xx As JsonObject = mycode.JsonObject_FtpEntry("d",fe.Name,fe.Size,fe.Timestamp)
                        result.PutJsonObject(xx)
                    Next
                End If
                If (Files<> Null And Files.Length>0) Then
                    For Each fe As FTPEntry In Files
                        Dim yy As JsonObject = mycode.JsonObject_FtpEntry("-", fe.Name,fe.Size, fe.Timestamp)
                        result.PutJsonObject(yy)
                        lastresult.PutJsonObject(yy)
                    Next
                End If
            End If
        End If
        
        ftp.Close
    End If
    
    Return result
End Sub

List result : Files() length = 0, Folders() length = 0

VSFTPD log
VSFTPD log on LIST:
Tue Feb 27 08:48:30 2024 [pid 154193] CONNECT: Client "202.137.6.19"
Tue Feb 27 08:48:30 2024 [pid 154193] FTP response: Client "202.137.6.19", "220 (vsFTPd 3.0.5)"
Tue Feb 27 08:48:30 2024 [pid 154193] FTP command: Client "202.137.6.19", "USER fromthesea"
Tue Feb 27 08:48:30 2024 [pid 154193] [fromthesea] FTP response: Client "202.137.6.19", "331 Please specify the password."
Tue Feb 27 08:48:30 2024 [pid 154193] [fromthesea] FTP command: Client "202.137.6.19", "PASS <password>"
Tue Feb 27 08:48:30 2024 [pid 154192] [fromthesea] OK LOGIN: Client "202.137.6.19"
Tue Feb 27 08:48:30 2024 [pid 154194] [fromthesea] FTP response: Client "202.137.6.19", "230 Login successful."
Tue Feb 27 08:48:30 2024 [pid 154194] [fromthesea] FTP command: Client "202.137.6.19", "SYST"
Tue Feb 27 08:48:30 2024 [pid 154194] [fromthesea] FTP response: Client "202.137.6.19", "215 UNIX Type: L8"
Tue Feb 27 08:48:30 2024 [pid 154194] [fromthesea] FTP command: Client "202.137.6.19", "PORT 172,18,11,218,143,41"
Tue Feb 27 08:48:30 2024 [pid 154194] [fromthesea] FTP response: Client "202.137.6.19", "500 Illegal PORT command."

Any suggestion what might wrong ?
 

rdkartono

Member
Licensed User
Longtime User
Sorry for very late reply. Had a lot of meetings last week.

I fixed the initialize method, including setting PasiveMode, UseSSL and UseSSLExplicit flags everytime ftp initialize.

So no more error from vsftp.log is recorded, however now I am investigating ftp.List command, the event ftp_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry) return success = true, but zero length for Folders() and Files().. meanwhile checking the same server and path from FileZilla has several files in it.
 
Upvote 0

rdkartono

Member
Licensed User
Longtime User
Its solved.

Adguard VPN for Android causing List return empty.
It used to block ads in browser, didn't think it cause trouble in FTP

I even write own library using common-net 3.10, but same result because of Adguard VPN.

So this thread may be closed. Thank you.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…