Android Question IP address confusing when upload file with FTP

Sergio83

Member
Licensed User
Hello everybody,

A few days ago I opened a thread about file transfering with the NET library FTP client and the Erel writen FTP server class. Erel gave me the solution to my issue at once (even à Sunday !!!), but now I'm facing a new issue regarding the FTP server IP address ...

Let me explain my network configuration:

1- FTP server is hosted by an Android TVBox wich is connected to my Internet access router via a wired connection (IP address is 192.168.1.6)

2- FTP client is hosted by an android smartphone which is wirelessly connected to the TVBox (via its wifi hotspot, the IP address is 192.168.43.1)

When I use the ethernet IP address of the TVBox (192.168.1.6) to initialize the FTP client and upload a file everyting works OK.

When I use the wifi hotspot IP address of the TVBox (192.168.43.1) to initialize the FTP client and upload a file I get this exception:

B4X:
java.IOException: Host attempting data connection 192.168.1.6 is not the same as server 192.168.43.1

Here after some pieces of code I use:

FTP client initialization

B4X:
FTP.Initialize("FTP", "192.168.43.1",51041, "admin", "admin")
FTP.PassiveMode = True

Upload command:

B4X:
Sub FTP_transfer_start(FilePath As String, FileName As String)
   
   FTP.UploadFile(FilePath, FileName, True, "/USB_DISK1/udisk0/domus/backup/"&FileName)

End Sub

Does anybody has an idea where I'm mistaken ?

Thanks by advance for your help

Regards
 

OliverA

Expert
Licensed User
I will make this test again tomorrow
I think I have it figured out now (with some help from @Erel here: https://www.b4x.com/android/forum/threads/reflection-vs-javaobject.84933/#post-537893). For step #2 in post #13 of this thread, the lines that need to be added to the Initialize sub are
B4X:
#If B4A
    Dim r As Reflector
    r.Target = socket
    Dim jo As JavaObject = r.GetField("socket")
#Else
    Dim jo As JavaObject = socket
    jo = jo.GetField("socket")
#End If
    jo = jo.RunMethod("getLocalAddress", Null) 'InetAddress
    IPAddress = jo.RunMethod("getHostAddress", Null)
#if debug
    Log(IPAddress)
#end if

In my case I placed the lines between the mServer = server and mDataPort lines and the start of the Initialize routine looks like this
B4X:
Public Sub Initialize (server As FTPServer, socket As Socket, DataPort As Int)
    mServer = server
#If B4A
    Dim r As Reflector
    r.Target = socket
    Dim jo As JavaObject = r.GetField("socket")
#Else
    Dim jo As JavaObject = socket
    jo = jo.GetField("socket")
#End If
    jo = jo.RunMethod("getLocalAddress", Null) 'InetAddress
    IPAddress = jo.RunMethod("getHostAddress", Null)
#if debug
    Log(IPAddress)
#end if
    mDataPort = DataPort
Please note that
  • The #if debug is just there for now to see the IP of the connection in debug mode
  • The Reflection library needs to be checked in B4A
I hope you get a chance to test this. If this works out, I may post the changes to the FTP Server's thread, since this should allow the FTP Server to properly handle connections in a multi-network card environment.
 
Upvote 0

sorex

Expert
Licensed User
May be I'm not clear enough in my explanations, or maybe I do not have the right level of expertise to understand your suggestion, but "my normal access point" is my HotSpot TVBox (using the Android tethering feature)

well, did you try with a laptop to connect to the tether hotspot and do a ftp file upload?

if the tethering blocks access to anything exept the gateway you can rewrite whatever you want but it just won't work.
 
Upvote 0

Sergio83

Member
Licensed User
Yes I did, with the IP adress of the TVBox (192.168.1.6) ,it works but not with the IP adress of the Hotspot (192.168.43.1)
 
Upvote 0

sorex

Expert
Licensed User
,it works but not with the IP adress of the Hotspot (192.168.43.1)

well then it's either the ftp server that's not listening on the 43.1 address or the hotspot that is doing its work correctly and block device to device traffic.
 
Upvote 0

Sergio83

Member
Licensed User
Hi OliverA,

I have good news for you this weekend. Your modification of the FTPClient module works perfectly for me. The FTP server reacts on both Ethernet and WiFi interfaces with the correct IP address.
Congratulations and many thanks for your help OliverA!

Best regards
 
Upvote 0
Top