crazyproton
crazyproton

Reputation: 163

FTP response 421 received. Server closed connection

I am writing a JAVA code to traverse FTP Location using Apache Commons Net FTPClient and getting output in an Excel file. the code execute correctly for approx 5 min but then gives an IOException:

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

I am using commons-net-3.0.1.jar. I have done some R&D and tried:

setDefaultTimeout(6000); 
setConnectTimeout(3000);
setSoTimeout(3000);
enterLocalPassiveMode();

and sending NOOP, but still getting the same error.

All I am trying to do is traverse through a directory and if file is found than get file name and file update date in excel else if directory is found then get inside and do until file is found again.

Please help and ask if any other information is required. I am new to JAVA.

Upvotes: 15

Views: 67613

Answers (2)

fiffy
fiffy

Reputation: 840

See here: http://kb.globalscape.com/KnowledgebaseArticle10142.aspx

    Error 421 Service not available, closing control connection. 
    Error 421 User limit reached 
    Error 421 You are not authorized to make the connection 
    Error 421 Max connections reached 
    Error 421 Max connections exceeded 

Maybe you're not reusing a connection but using a new connection for every request, flooding the server with connections until it hits the connection limit. Try closing your connections or resuing them.

Upvotes: 19

Mohd Abdul Mujib
Mohd Abdul Mujib

Reputation: 13928

For future reference..

If the solution by @fiffy didn't work, maybe try turning on the TLS (FTPS/Secure Connection), My server was set to only accept FTPS protocol, so it was rejecting my unencrypted connection, so turning on the TLS (FTPS) helped me solve the prob.

Note:- This error FTP response 421 received is very prominent in Netbeans since its also built in java.

Upvotes: 3

Related Questions