Android Question FTP Download not working

aklisiewicz

Active Member
Licensed User
Longtime User
Obviously I'm doing something wrong, but cannot figure out what

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim FTP As FTP
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("Layout1")
    Activity.LoadLayout("DownloadUpdates")
    Activity.Title = "Database Update"
    FTP.Initialize("FTP", "ftp.dps.com", 21, "android@dps.com","MyPassword")
End Sub

Sub lblDownload_Click
    FTP.DownloadFile("/public_html/android_db/edbq_rem.db", False, File.DirRootExternal, "edbq_rem.db")
End Sub

is there anything wrong with this code ?

the log generates:
-----------------------------------------------------
** Activity (downloadupdates) Create, isFirst = true **

** Activity (downloadupdates) Resume **

/public_html/android_db/edbq_lite_rem.db, Success=false

java.lang.RuntimeException: Error retrieving file.

500 I won't open a connection to 10.0.2.2 (only to 99.107.150.69)
----------------------------------------------------------------

BTW none of the IPs refers to the FTP server....






where do I call: FTP_DownloadProgress ?

Arthur
 
Last edited:

aklisiewicz

Active Member
Licensed User
Longtime User
yes it is public server, I use FileZilla to login and it works fine with the same credentials.
I tried IP address with the same Error result
Arthur
 
Upvote 0

aklisiewicz

Active Member
Licensed User
Longtime User
OK, where on a device am I supposed to look for downloaded file ? what folder ?
 
Upvote 0

aklisiewicz

Active Member
Licensed User
Longtime User
something is still wrong...
I checked DirRootExternal - the root folder on my SD card and the file is there but is is 0 bytes.
so there is no download...
the server permissions are set to 644 (hope this is enough)
I attached screenshoot from the debuger

Any ideas what could have be wrong ?

Arthur
 

Attachments

  • FTP_Error01.png
    46.6 KB · Views: 196
Upvote 0

aklisiewicz

Active Member
Licensed User
Longtime User
yes I have this Sub
B4X:
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then Log(LastException.Message)
End Sub
so what's the purpose ? how can I debug it ?
 
Last edited:
Upvote 0

aklisiewicz

Active Member
Licensed User
Longtime User
OK, I narrow it down to the Path problem on the server
looks like it is working now....

one more question ...

how would I show the progress ?
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Something like this:

B4X:
Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
     Dim zxs As String
 
     If Total > 0 Then
          zxs = "Downloaded " & Round(TotalDownloaded / 1000) & "KB, Out Of " & Round(Total / 1000) & "KB"
     Else
          zxs = "Downloaded " & Round(TotalDownloaded / 1000) & "KB"
     End If
 
     LBLStat.Text = zxs
End Sub
 
Last edited:
Upvote 0

aklisiewicz

Active Member
Licensed User
Longtime User
Got it,... I was missing this last line, forgot I need some screen label to show off....

I will sue the opportunity to resolve another issue....

I'm downloading SQLite database (single file).
There is a command to check SQLite database version. I need to compare it against existing database on a device. Is there any way to make a comparison before the download takes place so is the database is the same version the download will be skipped, so the user will not waste bandwidth limit.

Thanks a lot - Arthur
 
Last edited:
Upvote 0

Kintara

Member
Licensed User
Longtime User
hi,
I and doing a simular thing. The method I use is to have a CSV file on the server listing the latest versions available with Time and date of issue. The device keeps a simular list of the files it has down loaded.
It is then a simple matter of downloading the Server file and comparing it against the device file.
If its in the server file but not on the device - download
If its a newer one in the server file - download

Hope that helps
Im still playing with the code to make it happen.

Bob
 
Upvote 0

aklisiewicz

Active Member
Licensed User
Longtime User
I bet your solution will work but it seems like overkill for what I need. All I need is to compare the file date on the server and on the device (if the database version is hard top retrieve). The only question is how to check the file date on the server without downloading the file ?
Arthur
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
You should be able to get what you are looking for from FTP.List. See code below:

B4X:
FTP.List("Your server path goes here")
 
Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
     If Files.Length > 0 Then
          For i = 0 To Files.Length -1
               Log(Files(i).Name)
               Log(Files(i).Size)
               Log(Files(i).Timestamp)
          Next
     Else
          'do whatever is needed here
     End If
End Sub
 
Upvote 0

aklisiewicz

Active Member
Licensed User
Longtime User
Thank you Margret - I guess this is what I needed. Will test it and report back.
Arthur
 
Upvote 0

aldomoscarda

Member
Licensed User
Longtime User
Hello!!
Please help. I use the emulator. I try to download via ftp but does nothing, this is my code:
Sub Button7_Click
Msgbox("comienza descarga","")
Try
File.Delete(File.DirInternal , "emovil.zip")
Catch

End Try
Try
File.Delete(File.DirInternal , "emovil.txt")
Catch

End Try

FTP.Initialize("FTP", "192.168.1.175", 21, "EFARMA2", "ALDOmoscarda2610")

FTP.PassiveMode=False
FTP.DownloadFile("emovil.zip",False, File.DirDefaultExternal , "emovil.zip")
Msgbox("aparentemente solo me comunique sin descargar","")
End Sub
***********************************************************************
Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)

Dim s As String
s = "Descargando " & Round(TotalDownloaded / 1000) & "KB"
'Msgbox(s,"")
If Total > 0 Then s = s & " de " & Round(Total / 1000) & "KB"
EditText1.Hint =s

End Sub

thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…