B4J Question FTP-ERROR

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everyone,
I have a small project that connect to an ftp server, at the beginning worked perfect. Now i receive following error :
java.io.IOException: Host attempting data connection 62.231.125.150 is not same as server 62.231.125.2
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:755)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:557)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1716)
at anywheresoftware.b4a.net.FTPWrapper$2.run(FTPWrapper.java:239)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1589)
Here is my code :

B4X:
    Dim ftp As FTP
    ftp.Initialize("FTP","server",21,"xxxxxxxx","xxxxxxxx")
    ftp.PassiveMode = True
    Dim upl As Object=ftp.UploadFile("C:\Users\User\Downloads\","file.doc",False,"/serverpath/file.doc")
    Wait For(upl) ftp_UploadCompleted(serverPath As String, Success As Boolean)
    If Success Then
        ftp.Close
    Else
        ftp.Close
        Return
    End If
What is wrong in my code ? how can i solve ?
Thank you
 

teddybear

Well-Known Member
Licensed User
Try this code:

B4X:
    Dim ftp As FTP
    ftp.Initialize("FTP","server",21,"xxxxxxxx","xxxxxxxx")
    ftp.PassiveMode = True
    Dim jrf As Reflector
    jrf.Target=ftp
    jrf.GetField("client").As(JavaObject).RunMethod("setRemoteVerificationEnabled", Array(False))
    Dim upl As Object=ftp.UploadFile("C:\Users\User\Downloads\","file.doc",False,"/serverpath/file.doc")
    Wait For(upl) ftp_UploadCompleted(serverPath As String, Success As Boolean)
    If Success Then
        ftp.Close
    Else
        ftp.Close
        Return
    End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…