Android Question Net library, FTP and upload fails using mobile connection

Alexander Trowitzsch

Member
Licensed User
Longtime User
I am using the FTP part of the net library to upload a file containing GPS coordinates that will later be displayed on the web in a leaflet map marker.
It works without issues if I have connected the mobile to WIFI either in release or debug mode.
But switching off WIFI and activating mobile data connection does not work. These are the important parts:

Related parts:
Private Sub btnSend_Click
...
  ToastMessageShow("Uploading...",True)

    FTP.UploadFile(sDir, "gps.js", False, "/xy.com/abc/gps.js")

    ToastMessageShow("Listing...",True)

    FTP.List( "/xy.com/abc/")
...
End Sub


Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    ToastMessageShow("Listing completed: " & Success, True)
End Sub

Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    ToastMessageShow("Uploaded " & TotalUploaded & " bytes", True)
End Sub

Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success = False Then
        ToastMessageShow("Error uploading.", True)
    Else
        ToastMessageShow("Upload OK", True)
    End If
End Sub

With WIFI on all messages are shown in this order:
- "Uploading..."
- "Listing..."
- "Uploaded 66 bytes"
- "Upload ok"
- "Listing complete"
If I use mobile connection then only "Uploading..." and "Listing..." are shown. The events are never raised.
The strange thing is that the file 'gps.js' on the FTP Server IS created but has zero length. So it seems that the packet stream is blocked somehow or hangs.
But why? What's the differnce between WIFI and mobile data connection here?
 

Albert Kallal

Active Member
Licensed User
Well, can you try a different file extension? ".js" is often used for javascript - and LOTS of intervention can occur when you have anything that might represent a injection script. I would "run away" very fast from using a file extension with .js - they are high value file extensions in the web world for injection of scripts - don't go there - just don't! Change that file extension right now.

R
Albert
 
Upvote 0

Alexander Trowitzsch

Member
Licensed User
Longtime User
I'll try that. (Passive is already set.)
Yes, seems to be kinda sychronisation issue. I have a label in my activity constantly showing the actual GPS coordinates. If I call UploadFile with mobile connection then it stops responding. GPS_LocationChanged in the service module is obviously never called.
Thank you for replying even at weekends! :)
 
Upvote 0

Alexander Trowitzsch

Member
Licensed User
Longtime User
Well, can you try a different file extension? ".js" is often used for javascript - and LOTS of intervention can occur when you have anything that might represent a injection script. I would "run away" very fast from using a file extension with .js - they are high value file extensions in the web world for injection of scripts - don't go there - just don't! Change that file extension right now.

R
Albert
I know, I know. It's just a little test for a game with my children. ;) So I did not spend much time on it to implement a Web Service or things like that.

Hey Albert! Nice to see you here! Don't know if you remember me: Had also been an Access MVP round 2009. ?
Well, b4a sure is the easiest way to switch form VBA to Android.
Cheers!
 
Upvote 0

Albert Kallal

Active Member
Licensed User
I know, I know. It's just a little test for a game with my children. ;) So I did not spend much time on it to implement a Web Service or things like that.

Hey Albert! Nice to see you here! Don't know if you remember me: Had also been an Access MVP round 2009. ?
Well, b4a sure is the easiest way to switch form VBA to Android.
Cheers!

Yes - your name looks and sounds familiar. As for B4A? Yes, it really a great system - and given so many come from VB6, vb.net, VBA? Then B4A is really a nice and easy jump. I wish I was a larger fan of JavaScript - but I am not (and I do write and use js in my web applications - so I am not all that bad at writing js - but I still don't like it!!!). However, with B4A, we don't need to use + learn js. And we don't have to learn + use HTML, or XAML (zammal) markup like you do with most Android tools.

However, I would not have jumped on B4A if it was not its HUGE near all encompassing "marriage" to the Android platform. B4A is a great choice, but it would NOT be a great choice if it did not wind up creating native Android applications - and would not be a great choice without that "marriage" to the Android SDK and platform. When I realized how B4A works - and I was evaluating a few other dev tools (including a few that came from the Palm pilot world, and a few that came from windows CE that jumped over to Android. All of them were really bad - because they did not result in native Android applications. So their look + feel etc. was really poor.

B4A apps?
They feel like Android apps.
They run like Android apps.
They have a UI like Android apps.

And reason of course is because they ARE Android applications! If not for this reason - I probably would not be here!!!

Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada
 
Upvote 0

Alexander Trowitzsch

Member
Licensed User
Longtime User
Did it. And changed the extension from gps.js to gps.txt, deactivated all enery optimizations for the app.
The behaviour although does not really change. GPS_LocationChanged now raises repeatedly, but Wait For does not return and hangs.
Are there some permissions needed beneath INTERNET for mobile data connection? Tried additional ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE with no success.
 
Upvote 0

Alexander Trowitzsch

Member
Licensed User
Longtime User
Wait For never hangs (=freezes). It is possible that the event is not raised to the code will not be resumed.
Please post more code. Maybe you are not setting passive mode correctly.
Ok, I'll attach the complete project. Connection parameters of course altered.
 

Attachments

  • gpsftpupload.zip
    27.7 KB · Views: 241
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Ok, I'll attach the complete project. Connection parameters of course altered.
From the PassiveMode Tutorial

B4X:
FTP.Initialize(...)
FTP.PassiveMode = True

Your code
B4X:
    If FirstTime Then
        sDir=CallSub(Starter,"GetStorageDir")
        FTP.PassiveMode=True
        FTP.UseSSL=False
        FTP.Initialize("FTP", "ftp.xy.com", 21, "user@xy.com", "password")
    End If
 
Upvote 0
Top