Update (2017/10/17): For code changes that make this a true B4X update, see post #4
This relates to the FTP Server code posted here (https://www.b4x.com/android/forum/t...d-with-socket-and-asyncstreams.74320/#content).
@Sergio83 discovered an issue with the FTP server when it is deployed in a machine that has multiple active network cards (see https://www.b4x.com/android/forum/threads/ip-address-confusing-when-upload-file-with-ftp.84816/). In such an environment, it can happen that the FTPDataConnection may be assigned a different IP address than the FTPClient command connection, which will cause connection issues (as per the post linked above). With @Sergio83's help in testing the development and refining of a solution and @Erel's help in using Reflection vs JavaObject, the following code changes will allow for the proper handling of client connections:
1) Add a new variable in Class_Globals
2) Add the following lines to Initialize
3) Modify the Case "PASV" in the HandleClientCommand
Please note that
This relates to the FTP Server code posted here (https://www.b4x.com/android/forum/t...d-with-socket-and-asyncstreams.74320/#content).
@Sergio83 discovered an issue with the FTP server when it is deployed in a machine that has multiple active network cards (see https://www.b4x.com/android/forum/threads/ip-address-confusing-when-upload-file-with-ftp.84816/). In such an environment, it can happen that the FTPDataConnection may be assigned a different IP address than the FTPClient command connection, which will cause connection issues (as per the post linked above). With @Sergio83's help in testing the development and refining of a solution and @Erel's help in using Reflection vs JavaObject, the following code changes will allow for the proper handling of client connections:
1) Add a new variable in Class_Globals
B4X:
Private IPAddress As String
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
B4X:
Case "PASV"
PrepareDataConnection
'SendResponse (227, mServer.ssocket.GetMyIP.Replace(".", ",") & "," & Floor(mDataPort / 256) & "," & (mDataPort Mod 256))
SendResponse (227, IPAddress.Replace(".", ",") & "," & Floor(mDataPort / 256) & "," & (mDataPort Mod 256))
- 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
- This is a summary of these posts: (https://www.b4x.com/android/forum/t...-when-upload-file-with-ftp.84816/#post-537467) and (https://www.b4x.com/android/forum/t...upload-file-with-ftp.84816/page-2#post-538068).
Last edited: