Android Question FTP: I Can Transfer Files via Filezilla Client to FTP Server but not via B4A Code

Mahares

Expert
Licensed User
Longtime User
I can transfer files easily via FTP FIlezilla client on my PC to an FTP remote Filezilla Server set up by our IT fellow. But when I use my B4A code I get the following error: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.

To make sure the problem is not in my B4A code, I tested my code by sending files from my device to another FTP Filezilla server located in my home using WiFi. I can easily transfer files from device to my home server.

Does anyone have an idea what I should do next or how the IT guy should tweak his server..

Thank you in advance
 

barx

Well-Known Member
Licensed User
Longtime User
i would think it is just an incorrect setting
Check your settings in code against you filezilla site
Check things like passive / active mode too.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I use :
FTP.PassiveMode=True 'in my code
What other things to check besides: password and user name which are exactly the same when using Filezilla client and B4A.
One thing I noticed in Filezilla client log on PC, it shows these 2 lines:
Command: PASV
Response: 421 Could not create socket.

But there is no problem copying files from client to server despite that message. Is there a parallel between the 421 shown here and the 421 shown in my B4A exception
Thanks
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Check that the server uses FTP and not SFTP, check port number. Other than that, I'm not sure
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The server uses FTP and the port is confirmed: 21. Thanks for giving it a shot. I hope some of the FTP gurus on the forum can tackle this and reciprocate with their generosity and offer a solution.
Thanks.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Can be anything.

Was the PC session still open?

Maybe the system administrator limited it to only 1 connectios/session per user.

So disconnect all ftp clients and try again with the droid.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The PC session was not still open. There are no other ftp clients connected. I am actually working with the IT administrator one on one to help him sort this problem out and he is not limiting it to one user.
To summarize my problem: I can transfer files easily via FTP Filezilla client on my PC to an FTP remote Filezilla Server set up by our IT fellow. But when I use my B4A code I get the following error: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.
Keep the ideas coming. Thank you
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
see what happends with passive mode set to false, you only need that to connect to windows ftp servers if I recall right.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I'm out of ideas, searching the error on google; most threads point to passive mode mis-matches.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
worst case you have to send the credientials by private message so that we can have a look at it.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Changing the passivemode to False did the trick. I now can transfer and receive files via my device. If I understand you correctly: 'Use passivemode=False when Filezilla server, but Passivemode=true when Windows server.'. If that is the case, it is odd because at home I use Filezilla Server with Passivemode=True and it works.
Thank you very much Barx and Sorex for your help and perseverance.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i have exactly the same problem but "passivemode=False" didnot solve the problem :(

Error: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i have tried mobile network and wifi but same result
i am using filezilla and everything is working well

but from my app its not working...
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
Whenever one runs into this kind of problems, FTP, HTTP, NNTP or similar simple protocols, the first thing to do is to start up a telnet client and connect to the server on the correct port using that. Then, type the commands/requests manually, and see exactly what responses you get. Then, you know what you are working with on the other end.

Also useful is to make a tiny proxy app, where you connect to your app, which then connects to the server. Then, your app sits in the middle and listens to everything that's sent and recieved, and you can log it all. That should allow you to debug almost all network problems.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Another useful test is to download a FTP client app from Google Play and test it with it.

Make sure that the port is correct and that you are using the correct mode (plain, FTPS explicit or FTPS implicit).
hi erel, sorry for my late response

i tried now to install an ftp client app (FTP - Express)

and i can only connect if i choose FTPS explicit (see pic) then i get an error about unknown certificate and i press accept and then i can enter my files on my ftp account

now on my b4a app i use this code:

B4X:
        FTP.Initialize("FTP", "sagital.net", 21, "sagitvra", "xxxxxxxxxx") '/htdocs/lists/
            FTP.PassiveMode = True
            Log("try to send now")
            FTP.UploadFile(File.DirInternal, "/lists/" & btn.Tag & ".txt", True , "/public_html/lists/" & filestr & ".txt")

and get this error:

Error: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.

so what should i do to be able to enter my ftp account like i can in "FTP - Express"

1.png
2.png
3.png
4.png
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
i tried it now also like this and i get this error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

B4X:
            FTP.Initialize("FTP", "sagital.net", 21, "sagitvra", "xxxxxxxxxx") '/htdocs/lists/
            FTP.PassiveMode = True
            FTP.UseSSLExplicit = True
            Log("try to send now")
            FTP.UploadFile(File.DirInternal, "/lists/" & btn.Tag & ".txt", True , "/public_html/lists/" & filestr & ".txt")
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I know that you already switched to a different server. However this issue is solvable by setting a custom trust manager:
B4X:
Dim ctm As CustomTrustManager
ctm.InitializeAcceptAll
FTP.SetCustomSSLTrustManager(ctm)

thanx erel, i am now using a windows server, anyway your post will be maybe usefull for others so thanx a lot...
 
Upvote 0
Top