B4J Question FTP Server and Client - error file upload

Roberto P.

Well-Known Member
Licensed User
Longtime User
I made an example FTP server and client to try sending files on my local pc, but I have problems. Can anyone help me understand where the error is.
thank you

server side:
Sub AppStart (Args() As String)
    server.Initialize(Me, "FTPServer")
    server.SetPorts(51041, 51042, 51142)
    server.AddUser("Test", "test")
    'server.AddUser("anonymous", "") 'anonymous access
    'server.ForcedServerIp = "127.0.0.1" 'local access
    server.BaseDir = "c:\temp\ftp"
    server.Start
    server.ForcedServerIp = "127.0.0.1"
    StartMessageLoop
End Sub

Sub FTPServer_StateChanged
    Log($"Number of clients: ${server.NumberOfClients}"$)
End Sub


client SIDE:
Private Sub startftp
    
    mFtp.Initialize("", "127.0.0.1" , 51041, "Test", "test")
    'mFtp.Initialize("", "ftp.anse2000.it" , 21, "c1422", "c1422nI4ta2")
    
    Log( "isinizialized " & mFtp.IsInitialized)
    'Dim sf_send As Object         = mFtp.SendCommand("MKD", "/somefolder/newfolder")
    
    '"C:\B4J\works\B4JAnse2000\Objects\folderFiles"
    
    Dim sf As Object         = mFtp.UploadFile(File.DirApp, "c1422_ordfor.zip", False, "/c1422_ordfor.zip")
    
    Log("start upload ")
        
    Wait For (sf) ftp_UploadCompleted (ServerPath As String, Success As Boolean)
    
    Log("ServerPath = " & ServerPath)
    
    If Success Then
        Log("file was uploaded successfully")
    Else
        Log("Error uploading file")
    End If
    
    mFtp.Close
    
End Sub


isinizialized true
start upload
java.lang.RuntimeException: Error uploading file.
500 Unknown command: PORT
at anywheresoftware.b4a.net.FTPWrapper$2.run(FTPWrapper.java:241)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Make sure to set the client PassiveMode to True.


yes

B4X:
    mFtp.Initialize("", "localhost" , 21, "Test", "test")
    mFtp.PassiveMode = True



and this the result

isinizialized true
start upload
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:180)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:201)
at anywheresoftware.b4a.net.FTPWrapper.connectIfNeeded(FTPWrapper.java:493)
at anywheresoftware.b4a.net.FTPWrapper.access$3(FTPWrapper.java:485)
at anywheresoftware.b4a.net.FTPWrapper$2.run(FTPWrapper.java:225)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Have you tried to connect with an FTP Client like Filezilla?
Are you running server and client in the same computer?
Not sure if you should start the server in 127.0.0.0, probably it should it be in 192.168.x.x?
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
[SOLVED]

I used this params:

mFtp.PassiveMode = True
mFtp.UseSSL = False
mFtp.UseSSLExplicit = False

thank
 
Upvote 0
Top