Bug? ftp DownloadProgress

giannimaione

Well-Known Member
Licensed User
Longtime User
in sub:
Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)

Total is alway -1
 

LucaMs

Expert
Licensed User
Longtime User
This is not a bug.


I must copy (and translate) my answer to your same question in the Italian Forum ;)


Given this example in an Erel's tutorial:
B4X:
Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
    Dim s As String
    s = "Downloaded " & Round(TotalDownloaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
    Log(s)
End Sub

TotalDownloaded is the number of bytes currently downloaded.
Total is the file size. If you use Passive Mode, you get always -1.
You should set Passive Mode to False or you can get the file size using the FTP command List:
B4X:
FTP.List(mFTPServerUserFolder)

Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    If Success Then
        For Each f As FTPEntry In Files
            Log(f.Name & ":  " & NumberFormat2(f.Size, 1, 0, 0, True) & " Bytes")
        Next
    Else
        Log(LastException.Message)
    End If
End Sub
 
Last edited:
Top