Android Question FTP Error - java.net.SocketException: Connection reset

RickV

Member
Licensed User
Hi, I am using the latest jnet library and copied the code for the ftp server side and the b4a client side.

java.net.SocketException: Connection reset

I am receiving this error, and I am out of rope. I have no idea what to look for to determine the cause.

B4J part on Win 11 box, usernames and passwords set etc etc

Client side code
B4X:
            Starter.Ftp.Initialize("FTP", "192.168.1.240", 21, "zz", "zz")
            Starter.Ftp.PassiveMode = True
            Starter.Ftp.UseSSL = False
            Starter.Ftp.UseSSLExplicit = False
            Dim sf As Object = Starter.Ftp.UploadFile(File.Dirinternal, "temp.jpg", False, "/temp.jpg")
            'occurs here  -  java.net.SocketException: Connection reset

            Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
            Starter.Ftp.Close

Server side code
B4X:
    FTPSer.Initialize(Me, "FTPServer")
    FTPSer.SetPorts(21, 65500, 65535)
    FTPSer.AddUser("zz", "zz")
    FTPSer.BaseDir = IIf(xui.IsB4J, "c:\data\ftp", xui.DefaultFolder)
    FTPSer.BaseDir = "c:\data\ftp"
    xui.SetDataFolder(":\data\ftp")
    FTPSer.Start
    'loop bit removed as has UI
 

RickV

Member
Licensed User
Server side log
B4X:
Number of clients: 1
client: USER zz
client: PASS zz
User logged in: zz
client: TYPE I
client: PASV
java.net.SocketException: Software caused connection abort: socket write error
    at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
    at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:138)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AOUT.run(AsyncStreams.java:380)
    at java.base/java.lang.Thread.run(Thread.java:834)
java.net.SocketException: Software caused connection abort: recv failed
    at java.base/java.net.SocketInputStream.socketRead0(Native Method)
    at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:126)
    at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:232)
    at java.base/java.lang.Thread.run(Thread.java:834)
error: (SocketException) java.net.SocketException: Software caused connection abort: recv failed
error: (SocketException) java.net.SocketException: Software caused connection abort: recv failed
terminated
DataConnection_Close
Number of clients: 1
terminated
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Using ftptool or cmdline ftp checks whether the ftpserver is ok.
 
Upvote 0

RickV

Member
Licensed User
Using ftptool or cmdline ftp checks whether the ftpserver is ok.
Is ftptool an external to d4x? Where do I find fiptool?

Sorry Im pretty dumb when it comes to java, could you point me to some doc on the command line option for testing the ftp server operation please.

I have used windows file explorer ftp://192.168.1.240, log in with username and password and receive the error message attached.
 

Attachments

  • 0permissions.jpg
    0permissions.jpg
    32 KB · Views: 97
Upvote 0

RickV

Member
Licensed User
I installed a ftp client with some level of diagnostics, here is the logs...
What should I do do you think to resolve this ?
I dont have SSL certificates

B4X:
Connecting to 192.168.1.240:21...
Status:    Connection established, waiting for welcome message...
Response:    220 B4X FTP Server
Command:    AUTH TLS
Response:    451 Not logged in
Command:    AUTH SSL
Response:    451 Not logged in
Status:    Insecure server, it does not support FTP over TLS.
Command:    USER zz
Response:    331 
Command:    PASS **
Response:    230 
Command:    OPTS UTF8 ON
Response:    500 Unknown command: OPTS
Status:    Logged in
Status:    Retrieving directory listing...
Command:    PWD
Response:    257 "/"
Command:    TYPE I
Response:    200 
Command:    PASV
Error:    Disconnected from server: ECONNABORTED - Connection aborted
Error:    Failed to retrieve directory listing
 
Upvote 0

RickV

Member
Licensed User
furthermore, both end appear to stay connected, I can send a "custom command" from the ftp client being LIST, can even send "hello" and see it. I see that it appears in the b4j logs window immediately followed by the error below... for LIST that is.
(RuntimeException) java.lang.RuntimeException: Class instance was not initialized (ftpdataconnection)
so something isn't being made at the time of connection ???
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Don't use port 21, change ftp server port to 51041.(>1024)
 
Upvote 0
Solution
Top